void
/task<void>
is a special case here, because you can magic a void
from nowhere. You couldn't do the same with a int
, std::string
or similar.
void Bob()
{
create_task() { /* do stuff */ }.then([](){ /* do more stuff */ });
}
After this has returned /* do stuff */
and /* do more stuff */
have started, and any handle on their progress is discarded.
task<void> Bob()
{
return create_task() { /* do stuff */ }.then([](){ /* do more stuff */ });
}
After this has returned /* do stuff */
and /* do more stuff */
have started, and you have a handle to wait for them to finish.
int Alice()
{
return create_task() { /* do stuff */ }.then([](){ /* do more stuff */ return 42; }).get();
}
After this has returned /* do stuff */
and /* do more stuff */
have finished, with a final result available.
task<int> Alice()
{
return create_task() { /* do stuff */ }.then([](){ /* do more stuff */ return 42; });
}
After this has returned /* do stuff */
and /* do more stuff */
have started, and you have a handle to wait for them to finish, and get the result.