C/C++ API Reference
Loading...
Searching...
No Matches
pw::async2::experimental::Future< Derived, T > Class Template Reference

Overview

template<typename Derived, typename T>
class pw::async2::experimental::Future< Derived, T >

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.

Implementing

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.
Template Parameters
DerivedThe concrete class that implements this Future.
TThe type of the value returned by Pend upon completion.

Public Types

using value_type = T
 

Public Member Functions

Poll< value_type > Pend (Context &cx)
 
bool is_complete () const
 

Member Function Documentation

◆ is_complete()

template<typename Derived , typename T >
bool pw::async2::experimental::Future< Derived, T >::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.

◆ Pend()

template<typename Derived , typename T >
Poll< value_type > pw::async2::experimental::Future< Derived, T >::Pend ( Context cx)
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.


The documentation for this class was generated from the following file: