MCPcopy Create free account
hub / github.com/FastLED/FastLED / await

Function await

src/platforms/await.h:35–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33/// from any execution context (main thread, coroutine, worker thread).
34template<typename T>
35fl::task::PromiseResult<T> await(fl::task::Promise<T> promise) FL_NOEXCEPT {
36 // Validate promise
37 if (!promise.valid()) {
38 return fl::task::PromiseResult<T>(fl::task::Error("Invalid promise"));
39 }
40
41 // If already completed, return immediately
42 if (promise.is_completed()) {
43 return promise.is_resolved()
44 ? fl::task::PromiseResult<T>(promise.value())
45 : fl::task::PromiseResult<T>(promise.error());
46 }
47
48 auto& runtime = ICoroutineRuntime::instance();
49
50 // Poll until promise completes, yielding to platform scheduler
51 while (!promise.is_completed()) {
52 promise.update();
53 if (promise.is_completed()) break;
54 runtime.suspendMainthread(1000); // Yield ~1ms
55 }
56
57 // Promise completed, return result
58 return promise.is_resolved()
59 ? fl::task::PromiseResult<T>(promise.value())
60 : fl::task::PromiseResult<T>(promise.error());
61}
62
63} // namespace platforms
64} // namespace fl

Callers 2

FL_TEST_FILEFunction · 0.50
registerFunctionsMethod · 0.50

Calls 8

ErrorClass · 0.85
suspendMainthreadMethod · 0.80
validMethod · 0.45
is_completedMethod · 0.45
is_resolvedMethod · 0.45
valueMethod · 0.45
errorMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected