Talk:cpp/coroutine/coroutine traits
From cppreference.com
< Talk:cpp
Greetings!
We most likely expect the 'compute' function calculating 'a' and 'b' at the same time. Yet currently they are calculated one by one.
That's why we should write like this instead:
std::future<int> compute() { /* These don't block -> 2 threads*/ auto fa = std::async([] { return 6; }); auto fb = std::async([] { return 7; }); /* Blocking */ int a = co_await std::move(fa); int b = co_await std::move(fb); co_return a * b; };
--Gavrilikhin-d (talk) 08:22, 28 January 2021 (PST)