boost::capy::run_async

Bind an executor to produce a launcher. Invoke the launcher with a task to start it.

Synopsis

template<Executor Ex>
[[nodiscard]]
auto
run_async(Ex ex);

Description

Use this to start execution of a task<T> that was created lazily. The returned wrapper must be immediately invoked with the task; storing the wrapper and calling it later violates LIFO ordering.

Uses the default recycling frame allocator for coroutine frames. With no handlers, the result is discarded. An unhandled exception thrown by the task calls std::terminate. To catch it instead, pass an error handler that receives it as an exception_ptr, or co_await the work inside a coroutine.

Construct the task as the direct argument of the two‐call expression run_async(ex)(task).

Thread Safety

The wrapper itself should only be used from one thread.

Example

capy::task<void> my_task() { co_return; }

void start_task( capy::any_executor ex )
{
    capy::run_async(ex)(my_task());
}

Return Value

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

The return value should not be discarded.

Parameters

Name

Description

ex

The executor to execute the task on.

See Also