Helpers for interacting with multiples futures.
Learn more: Combinators
Classes | |
| class | pw::async2::JoinFuture< Futures > |
| class | pw::async2::SelectFuture< Futures > |
Macros | |
| #define | PW_SELECT(lhs, cx, ...) PW_TRY_READY_ASSIGN(lhs, ::pw::async2::internal::PendSelect(cx, __VA_ARGS__)) |
| #define | PW_CO_SELECT(lhs, ...) lhs = co_await ::pw::async2::internal::InPlaceSelectFuture(__VA_ARGS__) |
Functions | |
| template<typename... Futures> | |
| pw::async2::JoinFuture (Futures &&...) -> JoinFuture< Futures... > | |
| template<typename... Futures> | |
| constexpr auto | pw::async2::Join (Futures &&... futures) |
| template<typename... Futures> | |
| pw::async2::SelectFuture (Futures &&...) -> SelectFuture< Futures... > | |
| template<typename... Futures> | |
| SelectFuture< Futures... > | pw::async2::Select (Futures &&... futures) |
| #define PW_CO_SELECT | ( | lhs, | |
| ... | |||
| ) | lhs = co_await ::pw::async2::internal::InPlaceSelectFuture(__VA_ARGS__) |
Like PW_SELECT, but for use in coroutines.
PW_CO_SELECT suspends the coroutine until at least one of the futures completes, then assigns an OptionalTuple containing the outputs of every future that completed to lhs. Futures that did not complete stay pending and can be selected again.
The futures are referenced while the coroutine is suspended. This is safe for local variables of the coroutine, since coroutine frames never move. Like co_await on an lvalue future, other futures must outlive the PW_CO_SELECT and must not move while it is suspended.
| #define PW_SELECT | ( | lhs, | |
| cx, | |||
| ... | |||
| ) | PW_TRY_READY_ASSIGN(lhs, ::pw::async2::internal::PendSelect(cx, __VA_ARGS__)) |
Waits for the first of several futures to complete, without taking ownership of them.
PW_SELECT pends each of the futures in place. If none of them have completed, it returns Pending() from the current function. Otherwise, it assigns an OptionalTuple containing the outputs of every future that completed to lhs.
Unlike Select, PW_SELECT leaves the futures with their owner. Futures that did not complete stay pending and can be selected again, so timers keep their deadlines and in-progress operations are not cancelled. Only re-arm the futures that completed.
PW_SELECT. They are only referenced while PW_SELECT runs, so their owner may be moved between polls.has_value<I>(). More than one future may complete at once.PW_SELECT is a statement, not a future, so it can't be stored, returned, or passed to other combinators. Use Select when a future is needed, or call PW_SELECT from the Pend() function of a composite future.For coroutines, use PW_CO_SELECT.
|
constexpr |
Creates a future which pends the provided futures until all of them have completed.
When ready, the resulting future returns a tuple containing each future's output in the order the futures were provided.
| SelectFuture< Futures... > pw::async2::Select | ( | Futures &&... | futures | ) |
Runs each of the provided futures, resolving once the first has completed.
As additional futures may have completed during the time between the first completion and the task running, Select returns a Future<OptionalTuple> which stores the results of all the sub-futures which managed to complete.
Select takes ownership of its futures and destroys all of them once it completes, including those that did not complete. To wait on the same futures repeatedly, such as in a loop, use PW_SELECT or PW_CO_SELECT.