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

Function main

demo_example/ReadFiles.cpp:142–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142int main() {
143 std::vector<FileName> Files = {
144 "demo_example/Input/1.txt", "demo_example/Input/2.txt",
145 "demo_example/Input/3.txt", "demo_example/Input/4.txt",
146 "demo_example/Input/5.txt", "demo_example/Input/6.txt",
147 "demo_example/Input/7.txt", "demo_example/Input/8.txt",
148 "demo_example/Input/9.txt", "demo_example/Input/10.txt",
149 };
150
151 std::cout << "Calculating char counts synchronously.\n";
152 auto ResSync = CountCharInFiles(Files, 'x');
153 std::cout << "Files contain " << ResSync << " 'x' chars.\n";
154
155 executors::SimpleExecutor executor(4);
156 Promise<Unit> p;
157 auto future = p.getFuture();
158
159 std::cout << "Calculating char counts asynchronously by future.\n";
160 auto f = std::move(future).via(&executor).thenTry([&Files](auto &&) {
161 return CountCharInFilesAsync(Files, 'x').thenValue([](auto &&Value) {
162 std::cout << "Files contain " << Value << " 'x' chars.\n";
163 });
164 });
165
166 p.setValue(Unit());
167 f.wait();
168
169 std::cout << "Calculating char counts asynchronously by coroutine.\n";
170 auto ResCoro = syncAwait(CountCharInFilesCoro(Files, 'x'), &executor);
171 std::cout << "Files contain " << ResCoro << " 'x' chars.\n";
172
173 return 0;
174}

Callers

nothing calls this directly

Calls 11

CountCharInFilesFunction · 0.85
CountCharInFilesAsyncFunction · 0.85
UnitClass · 0.85
syncAwaitFunction · 0.85
CountCharInFilesCoroFunction · 0.85
getFutureMethod · 0.80
thenTryMethod · 0.80
viaMethod · 0.80
thenValueMethod · 0.80
setValueMethod · 0.80
waitMethod · 0.45

Tested by

no test coverage detected