uvco 0.1
|
#include <multipromise.h>
Classes | |
struct | MultiPromiseAwaiter_ |
Public Types | |
using | promise_type = Generator<T> |
Public Member Functions | |
MultiPromise (MultiPromise< T > &&) noexcept=default | |
An unfulfilled MultiPromise . | |
MultiPromise & | operator= (const MultiPromise< T > &)=delete |
MultiPromise & | operator= (MultiPromise< T > &&) noexcept=delete |
MultiPromise (const MultiPromise< T > &other)=default | |
~MultiPromise () | |
Promise< std::optional< T > > | next () |
MultiPromiseAwaiter_ | operator co_await () const |
bool | ready () |
void | cancel () |
Protected Types | |
using | PromiseCore_ = MultiPromiseCore<T> |
using | SharedCore_ = std::shared_ptr<PromiseCore_> |
Protected Member Functions | |
MultiPromise (SharedCore_ core) | |
Protected Attributes | |
SharedCore_ | core_ |
Friends | |
template<typename U > | |
class | Generator |
A MultiPromise
is like a Promise
, except that it can resolve more than just once. A coroutine returning a MultiPromise
(called a "generator
coroutine") uses co_yield
to return values to the awaiting coroutine. For example in the Udp
class, a method exists which generates packets.
As an adapter, for example for SelectSet, the next()
method returns a promise returning the next yielded value.
NOTE: currently uses a shared_ptr
PromiseCore, due to issues with inheritance. It is expected that normal Promise<T>
will be used most frequently, therefore the lack of optimization is not as grave.
using uvco::MultiPromise< T >::promise_type = Generator<T> |
Part of the coroutine protocol: the MultiPromise
is both return type and promise type.
|
protected |
|
protected |
|
defaultnoexcept |
An unfulfilled MultiPromise
.
It doesn't make sense to yield void. For that, just ues a normal coroutine (Promise<void>
) and repeatedly call it.
|
default |
|
inline |
|
inlineexplicitprotected |
|
inline |
Immediately cancel the suspended generator coroutine. This will drop all stack variables inside the generator (and run their destructors), and ensure that the generator will never resume from the currently yielded value.
cancel()
is called automatically once the (last) MultiPromise instance referring to a coroutine is destroyed.
(This can be solved by distinguishing between the returned object and the promise object, which may be part of a future refactor. In that case, the generator's promise object should only contain a weak reference to this MultiPromiseCore, and the caller contains a strong reference. The core's destructor cancels the generator once the caller doesn't require it anymore.)
|
inline |
Obtain the next value yielded by a generator coroutine. This is less efficient than awaiting the multipromise directly.
|
inline |
Return an awaiter for this MultiPromise, which resumes the waiting coroutine once the generator yields its next value.
Used when co_await
ing a MultiPromise created by a generator coroutine. The awaiter handles the actual suspension and resumption.
|
delete |
|
deletenoexcept |
|
inline |
|
protected |