mirror of
https://github.com/boostorg/cobalt.git
synced 2026-01-19 04:02:16 +00:00
25 lines
465 B
Plaintext
25 lines
465 B
Plaintext
== Tasks
|
|
|
|
<<task, Tasks>> are lazy, which means they won't do anything before awaited or spwaned.
|
|
|
|
[source,cpp]
|
|
----
|
|
cobalt::task<int> my_task()
|
|
{
|
|
co_await do_the_thing();
|
|
co_return 0;
|
|
}
|
|
|
|
cobalt::main co_main(int argc, char * argv[])
|
|
{
|
|
// create the task here
|
|
auto t = my_task();
|
|
// do something else here first
|
|
co_await do_the_other_thing();
|
|
// start and wait for the task to complete
|
|
auto res = co_wait t;
|
|
co_return res;
|
|
}
|
|
----
|
|
|