uvco 0.1
|
#include <select.h>
Public Types | |
using | Variant = std::variant<Promise<Ts>...> |
using | Tuple = std::tuple<Promise<Ts>...> |
Public Member Functions | |
SelectSet (Promise< Ts >... promises) | |
~SelectSet () | |
bool | await_ready () const noexcept |
void | await_suspend (std::coroutine_handle<> handle) |
std::vector< Variant > | await_resume () |
Private Member Functions | |
template<size_t Ix = 0> | |
void | checkPromises (std::vector< Variant > &readyPromises) |
Private Attributes | |
Tuple | promises_ |
bool | resumed_ = false |
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.
The SelectSet is directly awaitable. For example:
It is okay to add an already finished promise to a SelectSet.
It is possible that no events are returned ("spurious wakeup"); make sure that you can handle an empty result vector.
using uvco::SelectSet< Ts >::Tuple = std::tuple<Promise<Ts>...> |
using uvco::SelectSet< Ts >::Variant = std::variant<Promise<Ts>...> |
|
inlineexplicit |
|
inline |
|
inlinenoexcept |
|
inline |
Returns all promises that are ready. It is possible that no promise is ready, and the returned vector is empty, in the case that two promises were ready at once; one promise scheduled the SelectSet for resumption, we delivered both events, and will be woken up a second time.
TODO: provide a no-/rare-allocation API by reusing a vector or span.
|
inline |
Register the current coroutine to be resumed when one of the promises is ready.
|
inlineprivate |
|
private |
|
private |