wait_for
Creates a simple_future
out of a series of simple_future
s or reusable_future
s. This function will run all passed simple_future
s in parallel and return the results after all have complete. The dynamic overload requires all simple_future
s are of the same type.
template <typename T = void>
simple_future<T> future_value() noexcept
{
/* async behaviour goes here... */
co_return T{};
}
async_function
your_class::foo() noexcept
{
std::tuple<
details::promise_void,
bool,
std::optional<std::size_t>
> result = co_await wait_for(
engine_,
future_value<>(),
future_value<bool>(),
future_value<std::size_t>()
);
}
Unlike other simple_futures<T>
, wait_for
will always return the caller in the same thread as internally it uses an async_latch. Coroutine arguments are thread safe, so can return in any thread they choose.
-
template<typename ...Promises>
guaranteed_future<typename details::extract_promise_types<Promises...>::types> zab::wait_for(engine *_engine, Promises&&... _args) Given a variable amount of simple_promises, calls them in parallel and returns the results after all have complete.
- Parameters
_engine – The engine to use for setting up.
_thread – [in] The thread to return into.
_args – The simple_promises
- Template Parameters
Promises – The types of the simple_promises.
- Returns
A guaranteed_future that promises to get all of the results.
-
template<typename T>
guaranteed_future<std::vector<typename simple_future<T>::return_value>> zab::wait_for(engine *_engine, std::vector<simple_future<T>> &&_args)