C/C++ API Reference
Loading...
Searching...
No Matches
pw::async2::DerivedValueProvider< DerivedFuture > Class Template Referencefinal

Overview

template<typename DerivedFuture>
class pw::async2::DerivedValueProvider< DerivedFuture >

A generic provider that vends user-defined derived futures.

DerivedValueProvider allows attaching custom parameters to requests by using a class derived from ValueFuture. This enables the provider to inspect the parameters (e.g., requested size) and conditionally fulfill requests via ResolveIf.

Template Parameters
DerivedFutureThe user-defined future type. It must inherit from ValueFuture<T> and provide a constructor that accepts ValueFuture<T>&& as its first argument.
Inheritance diagram for pw::async2::DerivedValueProvider< DerivedFuture >:
pw::async2::ValueProvider< DerivedFuture::value_type >

Public Member Functions

template<typename... Args>
DerivedFuture Get (Args &&... args)
 Vends a derived future.
 
template<typename... Args>
std::optional< DerivedFuture > TryGet (Args &&... args)
 Vends a derived future if none is currently pending.
 
template<typename F >
bool ResolveIf (F &&callback)
 

Member Function Documentation

◆ ResolveIf()

template<typename DerivedFuture >
template<typename F >
bool pw::async2::DerivedValueProvider< DerivedFuture >::ResolveIf ( F &&  callback)
inline

Atomically inspects the derived future and resolves it if the callback returns a value indicating fulfillment.

The callback receives a reference to the DerivedFuture and should return a value indicating whether the request can be fulfilled:

  • For non-void futures (producing T), the callback should return std::optional<T>. Returning std::nullopt leaves the future pending.
  • For void futures, the callback should return bool. Returning false leaves the future pending.
Parameters
callbackA callable (lambda, function pointer, etc.) invoked with a reference to the DerivedFuture.
Returns
true if the future was resolved, false otherwise.

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