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

Function CountCharInFilesAsync

demo_example/ReadFiles.cpp:99–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99Future<uint64_t> CountCharInFilesAsync(const std::vector<FileName> &Files,
100 char c) {
101 // std::shared_ptr is necessary here. Since ReadSize may be used after
102 // CountCharInFilesAsync function ends.
103 auto ReadSize = std::make_shared<uint64_t>(0);
104 // We need to introduce another API `do_for_each` here.
105 return do_for_each(std::move(Files),
106 [ReadSize, c](auto &&File) {
107 return CountCharInFileAsyncImpl(File, c).thenValue(
108 [ReadSize](auto &&Size) {
109 *ReadSize += Size;
110 return makeReadyFuture();
111 });
112 })
113 .thenTry([ReadSize](auto &&) {
114 return makeReadyFuture<uint64_t>(*ReadSize);
115 });
116 ;
117}
118
119/////////////////////////////////////////
120/////////// Coroutine Part //////////////

Callers 1

mainFunction · 0.85

Calls 5

do_for_eachFunction · 0.85
CountCharInFileAsyncImplFunction · 0.85
makeReadyFutureFunction · 0.85
thenTryMethod · 0.80
thenValueMethod · 0.80

Tested by

no test coverage detected