69 p.complete_with_value(
value);
83 p.complete_with_error(
error);
109 return mImpl !=
nullptr;
116 if (!
valid())
return *
this;
126 if (!
valid())
return *
this;
135 if (!
valid())
return;
141 if (!
valid())
return false;
142 return mImpl->is_completed();
147 if (!
valid())
return false;
148 return mImpl->is_resolved();
153 if (!
valid())
return false;
154 return mImpl->is_rejected();
160 static const T default_value{};
161 return default_value;
163 return mImpl->value();
169 static const Error default_error;
170 return default_error;
172 return mImpl->error();
184 if (!
valid())
return false;
189 if (!
valid())
return false;
195 if (!
valid())
return false;
200 if (!
valid())
return false;
362 mState.store(
static_cast<int>(s));
Promise & operator=(const Promise &other)=default
Copy assignment operator.
static Promise< T > reject(const fl::string &error_message) FL_NOEXCEPT
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.
bool is_completed() const FL_NOEXCEPT
Check if Promise is completed (resolved or rejected)
const T & value() const FL_NOEXCEPT
Get the result value (only valid if is_resolved() returns true)
Promise(fl::shared_ptr< detail::PromiseImpl< T > > impl) FL_NOEXCEPT
Constructor from shared implementation (used internally)
Promise(Promise &&other) FL_NOEXCEPT=default
Move constructor.
Promise() FL_NOEXCEPT
Default constructor - creates invalid Promise.
Promise & catch_(fl::function< void(const Error &)> callback) FL_NOEXCEPT
Register error callback - returns reference for chaining.
const Error & error() const FL_NOEXCEPT
Get the error (only valid if is_rejected() returns true)
Promise(const Promise &other)=default
Copy constructor (promises are now copyable via shared implementation)
bool is_rejected() const FL_NOEXCEPT
Check if Promise is rejected (completed with error)
bool complete_with_value(const T &value) FL_NOEXCEPT
Complete the Promise with a result (used by networking library)
Promise & then(fl::function< void(const T &)> callback) FL_NOEXCEPT
Register success callback - returns reference for chaining.
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)
static Promise< T > reject(const Error &error) FL_NOEXCEPT
Create a rejected Promise with error.
void clear() FL_NOEXCEPT
Clear Promise to invalid state.
static Promise< T > create() FL_NOEXCEPT
Create a pending Promise.
bool valid() const FL_NOEXCEPT
Check if Promise is valid.
bool complete_with_error(const Error &error) FL_NOEXCEPT
Complete the Promise with an error (used by networking library)
void update() FL_NOEXCEPT
Update Promise state in main loop - should be called periodically This processes pending callbacks wh...
Promise & operator=(Promise &&other) FL_NOEXCEPT=default
Move assignment operator.
bool complete_with_error(const fl::string &error_message) FL_NOEXCEPT
bool is_resolved() const FL_NOEXCEPT
Check if Promise is resolved (completed successfully)
bool complete_with_value(T &&value) FL_NOEXCEPT
Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper arou...
bool is_rejected() const FL_NOEXCEPT
Check if Promise is rejected.
const T & value() const FL_NOEXCEPT
Get value (only valid if resolved)
const Error & error() const FL_NOEXCEPT
Get error (only valid if rejected)
bool reject(const Error &error) FL_NOEXCEPT
Reject Promise with error.
void set_then_callback(fl::function< void(const T &)> callback) FL_NOEXCEPT
Set success callback.
fl::function< void(const Error &)> mCatchCallback
PromiseImpl() FL_NOEXCEPT
void update() FL_NOEXCEPT
Update Promise state - processes callbacks if needed.
void process_callbacks() FL_NOEXCEPT
Process pending callbacks.
void set_state(PromiseState_t s) FL_NOEXCEPT
Write the state atomically.
bool resolve(T &&value) FL_NOEXCEPT
bool resolve(const T &value) FL_NOEXCEPT
Resolve Promise with value.
fl::function< void(const T &)> mThenCallback
PromiseState_t state() const FL_NOEXCEPT
Read the state atomically.
bool is_completed() const FL_NOEXCEPT
Check if Promise is completed.
void set_catch_callback(fl::function< void(const Error &)> callback) FL_NOEXCEPT
Set error callback.
bool is_resolved() const FL_NOEXCEPT
Check if Promise is resolved.
Implementation class for Promise - holds the actual state and logic.
Compile-time linker keep-alive hook for a single fl::Bus.
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
PromiseState_t
State enumeration for promises.
Promise< T > make_resolved_promise(T value) FL_NOEXCEPT
Convenience function to create a resolved Promise.
Promise< T > make_rejected_promise(const fl::string &error_message) FL_NOEXCEPT
Convenience function to create a rejected Promise.
constexpr int type_rank< T >::value
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Base definition for an LED controller.
Error(const char *msg) FL_NOEXCEPT
Error() FL_NOEXCEPT=default
bool is_empty() const FL_NOEXCEPT
Error(fl::string &&msg) FL_NOEXCEPT