FastLED 3.10.6
Loading...
Searching...
No Matches

◆ await()

template<typename T>
PromiseResult< T > fl::task::await ( Promise< T > p,
fl::u32 timeout_ms = fl::platforms::kAwaitDefaultTimeoutMs )
inline

Await promise completion in a coroutine (Trampoline to platform implementation)

Template Parameters
TThe type of value the promise resolves to
Parameters
pThe promise to await
Returns
A PromiseResult<T> containing either the resolved value or an error

This is the public API for awaiting promises in coroutines. It delegates to the platform-specific implementation in fl::platforms::await().

REQUIREMENTS:

  • MUST be called from within a fl::task::coroutine() context
  • Only available on ESP32 (FreeRTOS) and Host/Stub (std::thread) platforms
  • Promise MUST eventually complete (or timeout)

SAFETY: Unlike await_top_level(), this does NOT busy-wait. The coroutine is suspended by the OS scheduler and wakes when the promise completes, with zero CPU overhead.

Examples

.func = []() {
auto result = fl::task::await(fl::fetch_get("http://example.com"));
if (result.ok()) {
process(result.value());
}
}
});
Handle coroutine(const CoroutineConfig &config)
Creates and starts an OS-level coroutine task.
Definition task.cpp.hpp:364
PromiseResult< T > await(Promise< T > p, fl::u32 timeout_ms=fl::platforms::kAwaitDefaultTimeoutMs) FL_NO_EXCEPT
Await promise completion in a coroutine (Trampoline to platform implementation)
Definition executor.h:307
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
Parameters
timeout_msWall-clock budget before the wait returns an error rather than continuing to poll. Defaults to fl::platforms::kAwaitDefaultTimeoutMs; see FastLED#4369 for why the wait is bounded at all.

Definition at line 307 of file executor.h.

309 {
310 return fl::platforms::await(p, timeout_ms);
311}

References fl::FL_NO_EXCEPT.