Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Async & concurrency
  5. pw_async2
  6. Combinators
  7. pw::async2::SelectFuture< Futures > Class Template Reference
pw::async2::SelectFuture< Futures > Class Template Reference

Overview

template<typename... Futures>
class pw::async2::SelectFuture< Futures >

Future returned by Select() that polls multiple sub-futures until at least one completes.

SelectFuture owns its sub-futures by value and destroys all of them in place once Pend() returns Ready, cancelling any that did not complete.

Prefer constructing SelectFuture via Select(). To wait on the same futures repeatedly without destroying incomplete ones, use PW_SELECT or PW_CO_SELECT.

Public Types

using value_type = typename Traits::value_type
 

Public Member Functions

constexpr SelectFuture ()=default
 Constructs an empty, non-pendable SelectFuture.
 
template<bool kEnable = kValidFutures, std::enable_if_t< kEnable, int > = 0>
constexpr SelectFuture (Futures &&... futures)
 
 SelectFuture (const SelectFuture &)=delete
 
SelectFuture & operator= (const SelectFuture &)=delete
 
 SelectFuture (SelectFuture &&other) noexcept(kNothrowMove)
 
SelectFuture & operator= (SelectFuture &&other) noexcept(kNothrowMove)
 
 ~SelectFuture ()=default
 Destroys the SelectFuture, cancelling any active sub-futures.
 
Poll< value_type > Pend (Context &cx)
 
constexpr bool is_pendable () const
 
constexpr bool is_complete () const
 

Member Typedef Documentation

◆ value_type

template<typename... Futures>
using pw::async2::SelectFuture< Futures >::value_type = typename Traits::value_type

Output type (OptionalTuple<FutureValue<Futures>...>) produced on completion, holding the output of each sub-future that completed.

Constructor & Destructor Documentation

◆ SelectFuture() [1/2]

template<typename... Futures>
template<bool kEnable = kValidFutures, std::enable_if_t< kEnable, int > = 0>
constexpr pw::async2::SelectFuture< Futures >::SelectFuture ( Futures &&...  futures)
inlineexplicitconstexpr

Constructs a pendable SelectFuture that takes ownership of futures.

Parameters
[in]futuresThe sub-futures to poll concurrently.

◆ SelectFuture() [2/2]

template<typename... Futures>
pw::async2::SelectFuture< Futures >::SelectFuture ( SelectFuture< Futures > &&  other)
inlinenoexcept

Move-constructs a SelectFuture, leaving other empty.

Parameters
[in,out]otherThe SelectFuture to move from.

Member Function Documentation

◆ is_complete()

template<typename... Futures>
constexpr bool pw::async2::SelectFuture< Futures >::is_complete ( ) const
inlineconstexpr

Checks whether the SelectFuture has completed.

Returns
true if a previous call to Pend() returned Ready.

◆ is_pendable()

template<typename... Futures>
constexpr bool pw::async2::SelectFuture< Futures >::is_pendable ( ) const
inlineconstexpr

Checks whether Pend() may be called.

Returns
true if the SelectFuture holds active sub-futures and has not yet completed.

◆ operator=()

template<typename... Futures>
SelectFuture & pw::async2::SelectFuture< Futures >::operator= ( SelectFuture< Futures > &&  other)
inlinenoexcept

Move-assigns from other, cancelling and destroying any active sub-futures in this and leaving other empty.

Parameters
[in,out]otherThe SelectFuture to move from.
Returns
A reference to this.

◆ Pend()

template<typename... Futures>
Poll< value_type > pw::async2::SelectFuture< Futures >::Pend ( Context &  cx)
inline

Polls each pendable sub-future in order, completing once at least one returns Ready.

When Pend() returns Ready, all sub-futures (including any that did not complete) are immediately destroyed in place.

Precondition
is_pendable() is true and at least one sub-future is pendable.
Parameters
[in,out]cxThe asynchronous Context used to register wakers.
Returns
Ready with an OptionalTuple of all completed outputs if one or more sub-futures completed, or Pending otherwise.

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