A Future is an abstract handle to an asynchronous operation that is polled to completion. On completion, futures may return a value representing the result of the operation.
Futures are single-use and track their completion status. It is an error to poll a future after it has already completed.
The future class does not contain any members itself, providing only a core interface and delegating management to specific implementations.
In practice, developers will rarely derive from Future directly. Instead, they should use a more specific abstract future type like ListableFutureWithWaker, which manages common behaviors like waker storage.
Deriving from Future directly is necessary when these behaviors are not required; for example, when implementing a future that composes other futures.
Implementations derived directly from Future are required to provide the following member functions:
Poll<T> DoPend(Context& cx): Implements the asynchronous operation.void DoMarkComplete(): Marks the future as complete.bool DoIsComplete() const: Returns true if DoMarkCompleted has previously been called. This must always return a value, even if the future's provider has been destroyed.| Derived | The concrete class that implements this Future. |
| T | The type of the value returned by Pend upon completion. Use void for futures that do not return a value. |
Public Types | |
| using | value_type = std::conditional_t< std::is_void_v< T >, ReadyType, T > |
Public Member Functions | |
| Poll< value_type > | Pend (Context &cx) |
| bool | is_complete () const |
|
inline |
Returns true if the future has already returned a Ready result.
Calling Pend on a completed future will trigger an assertion.
|
inline |
Polls the future to advance its state.
Returns Pending if the future is not yet complete, or Ready with its result if it is.
If this future has already completed, calling Pend will trigger an assertion.