boost::capy::task
Lazy coroutine task satisfying IoRunnable.
Synopsis
Declared in <boost/capy/task.hpp>
template<typename T = void>
struct task;
Description
Use task<T> as the return type for coroutines that perform I/O and return a value of type T. The coroutine body does not start executing until the task is awaited, enabling efficient composition without unnecessary eager execution.
The task participates in the I/O awaitable protocol: when awaited, it receives the caller's executor and stop token, propagating them to nested co_await expressions. This enables cancellation and proper completion dispatch across executor boundaries.
Example
task<int> compute_value()
{
auto [ec, n] = co_await stream.read_some( buf );
if( ec )
co_return 0;
co_return process( buf, n );
}
task<> run_session( tcp_socket sock )
{
int result = co_await compute_value();
// ...
}
Member Functions
Name |
Description |
|
Move construct, transferring ownership. |
|
Destroy the task and its coroutine frame if owned. |
|
Move assign, transferring ownership. |
Return false; tasks are never immediately ready. |
|
Return the result or rethrow any stored exception. |
|
Start execution with the caller's context. |
|
Return the coroutine handle. |
|
Release ownership of the coroutine frame. |
Non-Member Functions
Name |
Description |
Execute multiple awaitables concurrently and collect their results. |
|
Wait for the first awaitable to complete (void range overload). |
|
Wait for the first awaitable to complete. |
|
Wait for the first awaitable to complete (range overload). |
See Also
IoRunnable, IoAwaitable, run, run_async
Created with MrDocs