2
0
mirror of https://github.com/boostorg/cobalt.git synced 2026-02-23 03:32:13 +00:00
Files
cobalt/doc/tour/task.adoc
Klemens Morgenstern 69867b8298 [doc] typo fixes.
2025-06-24 18:18:36 +08:00

25 lines
466 B
Plaintext

== Tasks
<<task, Tasks>> are lazy, which means they won't do anything before awaited or spawned.
[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_await t;
co_return res;
}
----