boost::capy::run_async

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

Synopsis

template<Executor Ex>
[[nodiscard]]
auto
run_async(
    Ex ex,
    std::stop_token st);

Description

The stop token is propagated to the task, enabling cooperative cancellation. With no handlers, the result is discarded and an unhandled exception calls std::terminate.

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> cancellable_task() { co_return; }

void run_with_cancellation( capy::any_executor ex )
{
    std::stop_source source;
    capy::run_async(ex, source.get_token())(cancellable_task());
    // Later: source.request_stop();
}

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.

st

The stop token for cooperative cancellation.

See Also