boost::capy::async_run

Creates a launcher coroutine to launch lazy tasks for detached execution.

Synopsis

template<
    dispatcher Dispatcher,
    frame_allocator Allocator = /* implementation-defined */>
/* implementation-defined */
async_run(
    Dispatcher,
    Allocator = {});

Description

Returns a suspended coroutine launcher whose frame is allocated BEFORE the user's task. This ensures the embedder (which lives on the launcher's stack frame) outlives the embedded wrapper in the user's task frame, preventing use‐after‐free bugs.

This implementation uses the "suspended coroutine launcher" pattern to achieve exactly two coroutine frames with guaranteed allocation order.

Usage

io_context ioc;
auto ex = ioc.get_executor();

// Fire and forget - discards result, rethrows exceptions
async_run(ex)(my_coroutine());

// With handler - captures result
async_run(ex)(compute_value(), [](int result) {
    std::cout << "Got: " << result << "\n";
});

// Awaitable mode - co_await to get result
task<void> caller(auto ex) {
    int result = co_await async_run(ex)(compute_value());
    std::cout << "Got: " << result << "\n";
}

ioc.run();

Return Value

A suspended async_run_launcher with operator() to launch tasks.

Parameters

Name Description

d

The dispatcher that schedules and resumes the task.

alloc

The frame allocator (default: recycling_frame_allocator).

See Also

async_run_launcher

task

dispatcher

Created with MrDocs