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

Detailed Description

template<typename T>
class fl::result< T >

Result type for promise operations.

Template Parameters
TThe success value type

result provides a clean API for handling success/error results from async operations. It wraps a Variant<T, Error> but provides more ergonomic access patterns with ok() checking and automatic assertions.

Usage

auto result = fl::await_top_level<int>(some_promise);
if (result.ok()) {
int value = result.value(); // Safe access
FL_WARN("Success: " << value);
} else {
FL_WARN("Error: " << result.error().message);
}
// Or use operator bool
if (result) {
FL_WARN("Got: " << result.value());
}
const Error & error() const
Get the error value.
const T & value() const
Get the success value (const)
result(const T &value)
Construct a successful result.
Result type for promise operations.
fl::result< T > await_top_level(fl::promise< T > promise)
Synchronously wait for a promise to complete (ONLY safe in top-level contexts)
Definition async.h:175
fl::string message
Definition promise.h:54
#define FL_WARN
Definition warn.h:12

Definition at line 40 of file promise_result.h.

#include <promise_result.h>

+ Collaboration diagram for fl::result< T >:

Public Member Functions

 result (const Error &error)
 Construct an error result.
 
 result (const T &value)
 Construct a successful result.
 
 result (Error &&error)
 Construct an error result (move)
 
 result (T &&value)
 Construct a successful result (move)
 
const Errorerror () const
 Get the error value.
 
fl::string error_message () const
 Get the error message as a convenience.
 
bool ok () const
 Check if the result is successful.
 
 operator bool () const
 Boolean conversion operator (same as ok())
 
T & value ()
 Get the success value (mutable)
 
const T & value () const
 Get the success value (const)
 
const fl::Variant< T, Error > & variant () const
 Access the underlying variant (for advanced usage)
 

Private Attributes

fl::Variant< T, ErrormResult
 

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