C/C++ API Reference
Loading...
Searching...
No Matches
pw::async2::ValueProvider< T > Class Template Reference

Overview

template<typename T>
class pw::async2::ValueProvider< T >

A one-to-one provider for a single value.

An ValueProvider can only vend one ValueFuture at a time.

This provider is multi-shot: after Resolve is called, a new future can be retrieved with Get to wait for the next Resolve event.

ValueProvider must resolve its future, if any, before it is destroyed. OptionalValueProvider, in contrast, supports cancelling its future.

Template Parameters
TThe type of value to provide.

Public Member Functions

 ValueProvider (ValueProvider &&other) noexcept
 
ValueProvideroperator= (ValueProvider &&other) noexcept
 
 ValueProvider (const ValueProvider &)=delete
 
ValueProvideroperator= (const ValueProvider &)=delete
 
ValueFuture< T > Get ()
 
std::optional< ValueFuture< T > > TryGet ()
 
bool has_future () const
 Returns true if the provider stores a pending future.
 
template<typename... Args, typename U = T, std::enable_if_t<!std::is_void_v< U >, int > = 0>
void Resolve (Args &&... args)
 
template<typename U = T, std::enable_if_t< std::is_void_v< U >, int > = 0>
void Resolve ()
 Resolves the pending ValueFuture.
 

Member Function Documentation

◆ Get()

template<typename T >
ValueFuture< T > pw::async2::ValueProvider< T >::Get ( )
inline

Returns a ValueFuture that will be completed when Resolve is called.

If a future has already been vended and is still pending, this crashes.

◆ Resolve()

template<typename T >
template<typename... Args, typename U = T, std::enable_if_t<!std::is_void_v< U >, int > = 0>
void pw::async2::ValueProvider< T >::Resolve ( Args &&...  args)
inline

Resolves the pending ValueFuture, if any, by constructing its value in-place.

◆ TryGet()

template<typename T >
std::optional< ValueFuture< T > > pw::async2::ValueProvider< T >::TryGet ( )
inline

Returns a ValueFuture that will be completed when Resolve is called.

If a future has already been vended and is still pending, this will return std::nullopt.


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