boost::capy::run_async

Asynchronously launch a lazy task with a result handler.

Synopsis

template<
    Executor Ex,
    /* implementation-defined */ H1>
[[nodiscard]]
auto
run_async(
    Ex ex,
    H1 h1);

Description

The handler h1 is called with the task's result on success. If h1 is also invocable with std::exception_ptr, it handles exceptions too. Otherwise, exceptions are rethrown.

Thread Safety

The handler may be called from any thread where the executor schedules work.

Example

// Handler for result only (exceptions rethrown)
run_async(ex, [](int result) {
    std::cout << "Got: " << result << "\n";
})(compute_value());

// Overloaded handler for both result and exception
run_async(ex, overloaded{
    [](int result) { std::cout << "Got: " << result << "\n"; },
    [](std::exception_ptr) { std::cout << "Failed\n"; }
})(compute_value());

Asynchronously launch a lazy task with custom allocator.

The allocator is wrapped in a frame_memory_resource and stored in the run_async_trampoline, ensuring it outlives all coroutine frames.

Return Value

A wrapper that accepts a task<T> for immediate execution.

Parameters

Name Description

ex

The executor to execute the task on.

h1

The handler to invoke with the result (and optionally exception).

alloc

The allocator for frame allocation (copied and stored).

See Also

task

executor

Created with MrDocs