WPILibC++ 2024.3.2
wpi::PromiseFactory< T > Class Template Reference

A promise factory for lightweight futures. More...

#include <wpi/future.h>

Inheritance diagram for wpi::PromiseFactory< T >:
wpi::detail::PromiseFactoryBase

Public Types

using ThenFunction = std::function< void(uint64_t, T)>
 

Public Member Functions

future< T > CreateFuture (uint64_t request)
 Creates a future. More...
 
future< T > MakeReadyFuture (T &&value)
 Creates a future and makes it immediately ready. More...
 
promise< T > CreatePromise (uint64_t request)
 Creates a promise. More...
 
void SetValue (uint64_t request, const T &value)
 Sets a value directly for a future without creating a promise object. More...
 
void SetValue (uint64_t request, T &&value)
 Sets a value directly for a future without creating a promise object. More...
 
void SetThen (uint64_t request, uint64_t outRequest, ThenFunction func)
 
bool IsReady (uint64_t request) noexcept
 
GetResult (uint64_t request)
 
void WaitResult (uint64_t request)
 
template<class Clock , class Duration >
bool WaitResultUntil (uint64_t request, const std::chrono::time_point< Clock, Duration > &timeout_time)
 
- Public Member Functions inherited from wpi::detail::PromiseFactoryBase
 ~PromiseFactoryBase ()
 
bool IsActive () const
 
wpi::mutexGetResultMutex ()
 
void Notify ()
 
void Wait (std::unique_lock< wpi::mutex > &lock)
 
template<class Clock , class Duration >
bool WaitUntil (std::unique_lock< wpi::mutex > &lock, const std::chrono::time_point< Clock, Duration > &timeout_time)
 
void IgnoreResult (uint64_t request)
 
uint64_t CreateRequest ()
 
bool EraseRequest (uint64_t request)
 
uint64_t CreateErasedRequest ()
 

Static Public Member Functions

static PromiseFactoryGetInstance ()
 

Friends

class future< T >
 

Detailed Description

template<typename T>
class wpi::PromiseFactory< T >

A promise factory for lightweight futures.

The lifetime of the factory must be ensured to be longer than any futures it creates.

Use CreateRequest() to create the future request id, and then CreateFuture() and CreatePromise() to create future and promise objects. A promise should only be created once for any given request id.

Template Parameters
Tthe "return" type of the promise/future

Member Typedef Documentation

◆ ThenFunction

template<typename T >
using wpi::PromiseFactory< T >::ThenFunction = std::function<void(uint64_t, T)>

Member Function Documentation

◆ CreateFuture()

template<typename T >
future< T > wpi::PromiseFactory< T >::CreateFuture ( uint64_t  request)
inline

Creates a future.

Parameters
requestthe request id returned by CreateRequest()
Returns
the future

◆ CreatePromise()

template<typename T >
promise< T > wpi::PromiseFactory< T >::CreatePromise ( uint64_t  request)
inline

Creates a promise.

Parameters
requestthe request id returned by CreateRequest()
Returns
the promise

◆ GetInstance()

template<typename T >
PromiseFactory< T > & wpi::PromiseFactory< T >::GetInstance
static

◆ GetResult()

template<typename T >
T wpi::PromiseFactory< T >::GetResult ( uint64_t  request)

◆ IsReady()

template<typename T >
bool wpi::PromiseFactory< T >::IsReady ( uint64_t  request)
noexcept

◆ MakeReadyFuture()

template<typename T >
future< T > wpi::PromiseFactory< T >::MakeReadyFuture ( T &&  value)

Creates a future and makes it immediately ready.

Returns
the future

◆ SetThen()

template<typename T >
void wpi::PromiseFactory< T >::SetThen ( uint64_t  request,
uint64_t  outRequest,
ThenFunction  func 
)

◆ SetValue() [1/2]

template<typename T >
void wpi::PromiseFactory< T >::SetValue ( uint64_t  request,
const T &  value 
)

Sets a value directly for a future without creating a promise object.

Identical to CreatePromise(request).set_value(value).

Parameters
requestrequest id, as returned by CreateRequest()
valuelvalue

◆ SetValue() [2/2]

template<typename T >
void wpi::PromiseFactory< T >::SetValue ( uint64_t  request,
T &&  value 
)

Sets a value directly for a future without creating a promise object.

Identical to CreatePromise(request).set_value(value).

Parameters
requestrequest id, as returned by CreateRequest()
valuervalue

◆ WaitResult()

template<typename T >
void wpi::PromiseFactory< T >::WaitResult ( uint64_t  request)

◆ WaitResultUntil()

template<typename T >
template<class Clock , class Duration >
bool wpi::PromiseFactory< T >::WaitResultUntil ( uint64_t  request,
const std::chrono::time_point< Clock, Duration > &  timeout_time 
)

Friends And Related Function Documentation

◆ future< T >

template<typename T >
friend class future< T >
friend

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