boost::capy::immediate
An awaitable that completes immediately with a value.
Synopsis
Declared in <boost/capy/ex/immediate.hpp>
template<class T>
struct immediate;
Description
This awaitable wraps a synchronous result so it can be used in contexts that require an awaitable type. It never suspends ‐ await_ready() always returns true, so the coroutine machinery is optimized away by the compiler.
Use this to adapt synchronous operations to satisfy async concepts like IoAwaitable without the overhead of a full coroutine frame.
Example
// Wrap a sync operation as an awaitable
immediate<int> get_value()
{
return {42};
}
task<void> example()
{
int x = co_await get_value(); // No suspension, returns 42
}
Satisfying WriteSink with sync operations
struct my_sync_sink
{
template<ConstBufferSequence CB>
immediate<io_result<std::size_t>>
write(CB buffers)
{
auto n = process_sync(buffers);
return {{{}, n}};
}
immediate<io_result<>>
write_eof()
{
return {{}};
}
};
Member Functions
Name |
Description |
Always returns true ‐ this awaitable never suspends. |
|
|
|
IoAwaitable protocol overload. |
Non-Member Functions
Name |
Description |
Create an immediate awaitable for a failed io_result. |
|
Create an immediate awaitable for a successful io_result with one value. |
|
Create an immediate awaitable for a successful io_result with three values. |
|
Create an immediate awaitable for a successful io_result with two values. |
|
Create an immediate awaitable for an io_result with error and three values. |
|
Create an immediate awaitable for an io_result with error and two values. |
|
Create an immediate awaitable for a successful io_result. |
|
Create an immediate awaitable for an io_result with error and one value. |
See Also
ready, io_result
Created with MrDocs