FastLED 3.9.15
|
Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper around a shared PromiseImpl for easy copying/sharing.
#include <promise.h>
Public Member Functions | |
promise () | |
Default constructor - creates invalid promise. | |
promise (const promise &other)=default | |
Copy constructor (promises are now copyable via shared implementation) | |
promise (promise &&other) noexcept=default | |
Move constructor. | |
promise & | catch_ (fl::function< void(const Error &)> callback) |
Register error callback - returns reference for chaining. | |
void | clear () |
Clear promise to invalid state. | |
bool | complete_with_error (const Error &error) |
Complete the promise with an error (used by networking library) | |
bool | complete_with_error (const fl::string &error_message) |
bool | complete_with_value (const T &value) |
Complete the promise with a result (used by networking library) | |
bool | complete_with_value (T &&value) |
const Error & | error () const |
Get the error (only valid if is_rejected() returns true) | |
bool | is_completed () const |
Check if promise is completed (resolved or rejected) | |
bool | is_rejected () const |
Check if promise is rejected (completed with error) | |
bool | is_resolved () const |
Check if promise is resolved (completed successfully) | |
promise & | operator= (const promise &other)=default |
Copy assignment operator. | |
promise & | operator= (promise &&other) noexcept=default |
Move assignment operator. | |
promise & | then (fl::function< void(const T &)> callback) |
Register success callback - returns reference for chaining. | |
void | update () |
Update promise state in main loop - should be called periodically This processes pending callbacks when the promise completes. | |
bool | valid () const |
Check if promise is valid. | |
const T & | value () const |
Get the result value (only valid if is_resolved() returns true) | |
Static Public Member Functions | |
static promise< T > | create () |
Create a pending promise. | |
static promise< T > | reject (const Error &error) |
Create a rejected promise with error. | |
static promise< T > | reject (const fl::string &error_message) |
Create a rejected promise with error message. | |
static promise< T > | resolve (const T &value) |
Create a resolved promise with value. | |
static promise< T > | resolve (T &&value) |
Create a resolved promise with value (move version) | |
Private Member Functions | |
promise (fl::shared_ptr< detail::PromiseImpl< T > > impl) | |
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. | |