template<typename... Ts>
class uvco::SelectSet< Ts >
A SelectSet is a set of promises that are awaited simultaneously. The first promise that is ready is returned. If no promise is ready, the coroutine is suspended until one of the promises is ready.
See also waitAny() for a more convenient approach that internally utilizes this class.
The SelectSet is directly awaitable. For example:
std::vector<std::variant<Promise<int>, Promise<int>>> results = co_await
ASSERT_EQ(2, results.size());
EXPECT_EQ(0, results[0].index());
EXPECT_EQ(1, std::get<0>(results[0]).unwrap());
std::vector<std::variant<int, int>> results2 =
co_await waitAny(promise1,
promise2); ASSERT_EQ(2, results.size()); EXPECT_EQ(0, results[0].index());
SelectSet(Promise< Ts > &...promises)
Definition select.h:61
Promise< std::vector< std::variant< PromiseTypes... > > > waitAny(Promise< PromiseTypes > &...promises)
Definition combinators.h:43
It is okay to add an already finished promise to a SelectSet.
A given SelectSet can only be awaited once. Usually, as shown above, it's best used as a temporary; it only takes references to the promises being selected from, and is therefore cheaply constructible.
It is possible that no events are returned ("spurious wakeup"); make sure that you can handle an empty result vector.