83 p.complete_with_value(
value);
97 p.complete_with_error(
error);
123 return mImpl !=
nullptr;
130 if (!
valid())
return *
this;
140 if (!
valid())
return *
this;
149 if (!
valid())
return;
155 if (!
valid())
return false;
156 return mImpl->is_completed();
161 if (!
valid())
return false;
162 return mImpl->is_resolved();
167 if (!
valid())
return false;
168 return mImpl->is_rejected();
174 static const T default_value{};
175 return default_value;
177 return mImpl->value();
183 static const Error default_error;
184 return default_error;
186 return mImpl->error();
198 if (!
valid())
return false;
203 if (!
valid())
return false;
209 if (!
valid())
return false;
214 if (!
valid())
return false;
void process_callbacks()
Process pending callbacks.
void update()
Update promise state - processes callbacks if needed.
bool is_completed() const
Check if promise is completed.
void set_then_callback(fl::function< void(const T &)> callback)
Set success callback.
bool is_resolved() const
Check if promise is resolved.
const T & value() const
Get value (only valid if resolved)
bool reject(const Error &error)
Reject promise with error.
const Error & error() const
Get error (only valid if rejected)
bool is_rejected() const
Check if promise is rejected.
fl::function< void(const T &)> mThenCallback
fl::function< void(const Error &)> mCatchCallback
bool resolve(const T &value)
Resolve promise with value.
void set_catch_callback(fl::function< void(const Error &)> callback)
Set error callback.
Implementation class for promise - holds the actual state and logic.
static promise< T > create()
Create a pending promise.
promise(const promise &other)=default
Copy constructor (promises are now copyable via shared implementation)
const Error & error() const
Get the error (only valid if is_rejected() returns true)
void update()
Update promise state in main loop - should be called periodically This processes pending callbacks wh...
bool complete_with_value(const T &value)
Complete the promise with a result (used by networking library)
promise & catch_(fl::function< void(const Error &)> callback)
Register error callback - returns reference for chaining.
bool is_resolved() const
Check if promise is resolved (completed successfully)
promise(promise &&other) noexcept=default
Move constructor.
promise()
Default constructor - creates invalid promise.
bool complete_with_error(const Error &error)
Complete the promise with an error (used by networking library)
static promise< T > resolve(const T &value)
Create a resolved promise with value.
static promise< T > reject(const Error &error)
Create a rejected promise with error.
bool complete_with_value(T &&value)
promise(fl::shared_ptr< detail::PromiseImpl< T > > impl)
Constructor from shared implementation (used internally)
bool is_rejected() const
Check if promise is rejected (completed with error)
void clear()
Clear promise to invalid state.
promise & operator=(promise &&other) noexcept=default
Move assignment operator.
bool valid() const
Check if promise is valid.
bool complete_with_error(const fl::string &error_message)
const T & value() const
Get the result value (only valid if is_resolved() returns true)
promise & operator=(const promise &other)=default
Copy assignment operator.
static promise< T > resolve(T &&value)
Create a resolved promise with value (move version)
static promise< T > reject(const fl::string &error_message)
Create a rejected promise with error message.
fl::shared_ptr< detail::PromiseImpl< T > > mImpl
Shared pointer to implementation - this allows copying and sharing promise state.
promise & then(fl::function< void(const T &)> callback)
Register success callback - returns reference for chaining.
bool is_completed() const
Check if promise is completed (resolved or rejected)
Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper arou...
Implements the FastLED namespace macros.
PromiseState_t
State enumeration for promises.
constexpr remove_reference< T >::type && move(T &&t) noexcept
promise< T > make_resolved_promise(T value)
Convenience function to create a resolved promise.
shared_ptr< T > make_shared(Args &&... args)
promise< T > make_rejected_promise(const fl::string &error_message)
Convenience function to create a rejected promise.
Error(const fl::string &msg)