MCPcopy Create free account
hub / github.com/apache/arrow / All

Function All

cpp/src/arrow/util/future.h:709–737  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

707/// will be stored in the result vector alongside successful results.
708template <typename T>
709Future<std::vector<Result<T>>> All(std::vector<Future<T>> futures) {
710 struct State {
711 explicit State(std::vector<Future<T>> f)
712 : futures(std::move(f)), n_remaining(futures.size()) {}
713
714 std::vector<Future<T>> futures;
715 std::atomic<size_t> n_remaining;
716 };
717
718 if (futures.size() == 0) {
719 return {std::vector<Result<T>>{}};
720 }
721
722 auto state = std::make_shared<State>(std::move(futures));
723
724 auto out = Future<std::vector<Result<T>>>::Make();
725 for (const Future<T>& future : state->futures) {
726 future.AddCallback([state, out](const Result<T>&) mutable {
727 if (state->n_remaining.fetch_sub(1) != 1) return;
728
729 std::vector<Result<T>> results(state->futures.size());
730 for (size_t i = 0; i < results.size(); ++i) {
731 results[i] = state->futures[i].result();
732 }
733 out.MarkFinished(std::move(results));
734 });
735 }
736 return out;
737}
738
739/// \brief Create a Future which completes when all of `futures` complete.
740///

Callers 5

ParallelForAsyncFunction · 0.70
TEST_PFunction · 0.70
TESTFunction · 0.70
AllFinishedFunction · 0.70
operator()Method · 0.50

Calls 5

MakeFunction · 0.70
sizeMethod · 0.45
AddCallbackMethod · 0.45
resultMethod · 0.45
MarkFinishedMethod · 0.45

Tested by 2

TEST_PFunction · 0.56
TESTFunction · 0.56