Skip to content

Commit

Permalink
update readme and example
Browse files Browse the repository at this point in the history
  • Loading branch information
coyorkdow committed Nov 3, 2024
1 parent ec35ba0 commit 447e549
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int main() {
With a scheduler we can run multiple coroutines simultaneously.
The following snippet shows a task receives the results from two delayed subtasks.
Each subtask will spend 1 second to return. And the main task have to wait until both subtasks return their results.
The main task also spend 1 second to do its own stuff which is independent to the subtasks.
By scheduling this task with a scheduler that has three worker threads, we can get the final result in one second.
Because we can have two subtasks run in parallel.
```c++
Expand All @@ -43,6 +44,7 @@ coro::task<int> slow_response(int a, int b) {
};
coro::task<int> resp1 = co_await coro::this_scheduler::parallel(request(a));
coro::task<int> resp2 = co_await coro::this_scheduler::parallel(request(b));
std::this_thread::sleep_for(1s);
co_return co_await std::move(resp1) + co_await std::move(resp2);
}
Expand Down
2 changes: 1 addition & 1 deletion test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ coro::task<int> slow_response(int a, int b) {
};
coro::task<int> resp1 = co_await coro::this_scheduler::parallel(request(a));
coro::task<int> resp2 = co_await coro::this_scheduler::parallel(request(b));
// std::this_thread::sleep_for(1s);
std::this_thread::sleep_for(1s);
co_return co_await std::move(resp1) + co_await std::move(resp2);
}

Expand Down

0 comments on commit 447e549

Please sign in to comment.