MCPcopy Create free account
hub / github.com/alibaba/async_simple / do_for_each

Function do_for_each

demo_example/ReadFiles.cpp:67–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65// It is not travial to implement an asynchronous do_for_each.
66template <typename InputIt, typename Callable>
67Future<void> do_for_each(InputIt Begin, InputIt End, Callable func) {
68 for (auto It = Begin; It != End; ++It) {
69 auto F = std::invoke(func, *It);
70 // If we met an error, return early.
71 if (F.result().hasError())
72 return F;
73 if (F.hasResult())
74 continue;
75 return std::move(F).thenTry(
76 [SubBegin = ++It, SubEnd = End, func](auto &&) {
77 return do_for_each(SubBegin, SubEnd, func);
78 });
79 }
80 return makeReadyFuture();
81}
82
83template <Range RangeTy, typename Callable>
84Future<void> do_for_each(const RangeTy &Rng, Callable func) {

Callers 1

CountCharInFilesAsyncFunction · 0.85

Calls 8

invokeFunction · 0.85
makeReadyFutureFunction · 0.85
thenTryMethod · 0.80
hasErrorMethod · 0.45
resultMethod · 0.45
hasResultMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected