boost::capy::immediate

An awaitable that completes immediately with a value.

Synopsis

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

await_ready

Always returns true ‐ this awaitable never suspends.

await_resume

await_resume overloads

await_suspend

IoAwaitable protocol overload.

Data Members

Name

Description

value_

The wrapped value.

Non-Member Functions

Name

Description

ready

Create an immediate awaitable for a failed io_result.

ready

Create an immediate awaitable for a successful io_result with one value.

ready

Create an immediate awaitable for a successful io_result with three values.

ready

Create an immediate awaitable for a successful io_result with two values.

ready

Create an immediate awaitable for an io_result with error and three values.

ready

Create an immediate awaitable for an io_result with error and two values.

ready

Create an immediate awaitable for a successful io_result.

ready

Create an immediate awaitable for an io_result with error and one value.

Template Parameters

Name Description

T

The result type to wrap.

See Also

ready, io_result

Created with MrDocs