WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
wpi::PromiseFactory< T > Class Template Reference

A promise factory for lightweight futures. More...

#include <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
bool IsActive () const
 
wpi::mutex & GetResultMutex ()
 
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 Function Documentation

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
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
template<typename T>
future< T > wpi::PromiseFactory< T >::MakeReadyFuture ( T &&  value)

Creates a future and makes it immediately ready.

Returns
the future
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
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

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