A promise factory for lightweight futures. More...
#include <wpi/future.h>
Public Types | |
using | ThenFunction = std::function<void(uint64_t, T)> |
Public Member Functions | |
future< T > | CreateFuture (uint64_t request) |
Creates a future. | |
future< T > | MakeReadyFuture (T &&value) |
Creates a future and makes it immediately ready. | |
promise< T > | CreatePromise (uint64_t request) |
Creates a promise. | |
void | SetValue (uint64_t request, const T &value) |
Sets a value directly for a future without creating a promise object. | |
void | SetValue (uint64_t request, T &&value) |
Sets a value directly for a future without creating a promise object. | |
void | SetThen (uint64_t request, uint64_t outRequest, ThenFunction func) |
bool | IsReady (uint64_t request) noexcept |
T | 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) |
![]() | |
~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 PromiseFactory & | GetInstance () |
Friends | |
class | future< 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.
T | the "return" type of the promise/future |
using wpi::PromiseFactory< T >::ThenFunction = std::function<void(uint64_t, T)> |
|
inline |
|
inline |
|
static |
T wpi::PromiseFactory< T >::GetResult | ( | uint64_t | request | ) |
|
noexcept |
future< T > wpi::PromiseFactory< T >::MakeReadyFuture | ( | T && | value | ) |
Creates a future and makes it immediately ready.
void wpi::PromiseFactory< T >::SetThen | ( | uint64_t | request, |
uint64_t | outRequest, | ||
ThenFunction | func ) |
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)
.
request | request id, as returned by CreateRequest() |
value | lvalue |
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)
.
request | request id, as returned by CreateRequest() |
value | rvalue |
void wpi::PromiseFactory< T >::WaitResult | ( | uint64_t | request | ) |
bool wpi::PromiseFactory< T >::WaitResultUntil | ( | uint64_t | request, |
const std::chrono::time_point< Clock, Duration > & | timeout_time ) |
|
friend |