boost::capy::run_async

Asynchronously launch a lazy task with separate result and error handlers.

Synopsis

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

Description

The handler h1 is called with the task's result on success. The handler h2 is called with the exception_ptr on failure.

Thread Safety

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

Example

run_async(ex,
    [](int result) { std::cout << "Got: " << result << "\n"; },
    [](std::exception_ptr ep) {
        try { std::rethrow_exception(ep); }
        catch (std::exception const& e) {
            std::cout << "Error: " << e.what() << "\n";
        }
    }
)(compute_value());

Asynchronously launch a lazy task with allocator and handler.

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 on success.

h2

The handler to invoke with the exception on failure.

alloc

The allocator for frame allocation (copied and stored).

See Also

task

executor

Created with MrDocs