boost::capy::run_async

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

Synopsis

template<
    Executor Ex,
    class H1>
requires detail::RunAsyncHandler<H1>
[[nodiscard]]
auto
run_async(
    Ex ex,
    std::stop_token st,
    H1 h1);

Description

The stop token is propagated to the task for cooperative cancellation. The handler h1 is called with the result on success, and optionally with exception_ptr if it accepts that type.

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. The handlers may be invoked from any thread where the executor schedules work.

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.

h1

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

See Also