FastLED 3.9.15
Loading...
Searching...
No Matches
promise.h File Reference

Detailed Description

Promise-based fluent API for FastLED - standalone async primitives.

The fl::promise<T> API provides fluent .then() semantics that are intuitive and chainable for async operations in FastLED. This is a lightweight, standalone implementation that doesn't depend on fl::future.

Features

  • Fluent API: Chainable .then() and .catch_() methods
  • Non-Blocking: Perfect for setup() + loop() programming model
  • Lightweight: Standalone implementation without heavy dependencies
  • JavaScript-Like: Familiar Promise API patterns

Usage

// HTTP request with promise-based API
fl::http_get("http://fastled.io")
.then([](const Response& resp) {
FL_WARN("Success: " << resp.text());
})
.catch_([](const Error& err) {
FL_WARN("Error: " << err.message());
});
#define FL_WARN
Definition warn.h:12

Interface

// Chainable operations
fl::fetch.get("http://api.example.com/data")
.header("Authorization", "Bearer token123")
.timeout(5000)
.then([](const Response& resp) {
if (resp.ok()) {
process_data(resp.text());
}
})
.catch_([](const Error& err) {
handle_error(err.message());
});
void fetch(const fl::string &url, const FetchCallback &callback)
Make an HTTP GET request (cross-platform, backward compatible)
Definition fetch.cpp:63

Definition in file promise.h.

#include "fl/namespace.h"
#include "fl/function.h"
#include "fl/string.h"
#include "fl/shared_ptr.h"
#include "fl/move.h"
+ Include dependency graph for promise.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  fl::detail::PromiseImpl< T >
 Implementation class for promise - holds the actual state and logic. More...
 
struct  fl::Error
 Error type for promises. More...
 
class  fl::promise< T >
 Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper around a shared PromiseImpl for easy copying/sharing. More...
 

Namespaces

namespace  fl
 IMPORTANT!
 
namespace  fl::detail
 

Enumerations

enum class  fl::detail::PromiseState_t { fl::detail::PENDING , fl::detail::RESOLVED , fl::detail::REJECTED }
 State enumeration for promises. More...
 

Functions

template<typename T>
promise< T > fl::make_rejected_promise (const char *error_message)
 Convenience function to create a rejected promise (const char* overload)
 
template<typename T>
promise< T > fl::make_rejected_promise (const fl::string &error_message)
 Convenience function to create a rejected promise.
 
template<typename T>
promise< T > fl::make_resolved_promise (T value)
 Convenience function to create a resolved promise.