FastLED 3.9.15
Loading...
Searching...
No Matches
fl::task::Promise< T > Class Template Reference

Detailed Description

template<typename T>
class fl::task::Promise< T >

Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper around a shared PromiseImpl for easy copying/sharing.

Definition at line 58 of file promise.h.

#include <promise.h>

+ Inheritance diagram for fl::task::Promise< T >:
+ Collaboration diagram for fl::task::Promise< T >:

Public Member Functions

 Promise () FL_NOEXCEPT
 Default constructor - creates invalid Promise.
 
 Promise (const Promise &other)=default
 Copy constructor (promises are now copyable via shared implementation)
 
 Promise (Promise &&other) FL_NOEXCEPT=default
 Move constructor.
 
Promisecatch_ (fl::function< void(const Error &)> callback) FL_NOEXCEPT
 Register error callback - returns reference for chaining.
 
void clear () FL_NOEXCEPT
 Clear Promise to invalid state.
 
bool complete_with_error (const Error &error) FL_NOEXCEPT
 Complete the Promise with an error (used by networking library)
 
bool complete_with_error (const fl::string &error_message) FL_NOEXCEPT
 
bool complete_with_value (const T &value) FL_NOEXCEPT
 Complete the Promise with a result (used by networking library)
 
bool complete_with_value (T &&value) FL_NOEXCEPT
 
const Errorerror () const FL_NOEXCEPT
 Get the error (only valid if is_rejected() returns true)
 
bool is_completed () const FL_NOEXCEPT
 Check if Promise is completed (resolved or rejected)
 
bool is_rejected () const FL_NOEXCEPT
 Check if Promise is rejected (completed with error)
 
bool is_resolved () const FL_NOEXCEPT
 Check if Promise is resolved (completed successfully)
 
Promiseoperator= (const Promise &other)=default
 Copy assignment operator.
 
Promiseoperator= (Promise &&other) FL_NOEXCEPT=default
 Move assignment operator.
 
Promisethen (fl::function< void(const T &)> callback) FL_NOEXCEPT
 Register success callback - returns reference for chaining.
 
void update () FL_NOEXCEPT
 Update Promise state in main loop - should be called periodically This processes pending callbacks when the Promise completes.
 
bool valid () const FL_NOEXCEPT
 Check if Promise is valid.
 
const T & value () const FL_NOEXCEPT
 Get the result value (only valid if is_resolved() returns true)
 

Static Public Member Functions

static Promise< T > create () FL_NOEXCEPT
 Create a pending Promise.
 
static Promise< T > reject (const Error &error) FL_NOEXCEPT
 Create a rejected Promise with error.
 
static Promise< T > reject (const fl::string &error_message) FL_NOEXCEPT
 Create a rejected Promise with error message.
 
static Promise< T > resolve (const T &value) FL_NOEXCEPT
 Create a resolved Promise with value.
 
static Promise< T > resolve (T &&value) FL_NOEXCEPT
 Create a resolved Promise with value (move version)
 

Private Member Functions

 Promise (fl::shared_ptr< detail::PromiseImpl< T > > impl) FL_NOEXCEPT
 Constructor from shared implementation (used internally)
 

Private Attributes

fl::shared_ptr< detail::PromiseImpl< T > > mImpl
 Shared pointer to implementation - this allows copying and sharing Promise state.
 

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