boost::capy::run_async
Asynchronously launch a lazy task with a result handler.
Synopsis
Declared in <boost/capy/ex/run_async.hpp>
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.
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.
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). |