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

Function loop

examples/Asio/Client/ClientReal.h:358–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

356}
357
358void loop() {
359 // TUTORIAL: Cycle between different async approaches every 10 seconds
360 // This allows you to see both promise-based and await-based patterns in action
361 // The LEDs provide visual feedback about which approach succeeded
362
363 unsigned long current_time = fl::millis();
364
365 // Switch approaches every 10 seconds
366 // 4 different approaches: Promise, Await, JSON Promise, JSON Await
367 if (current_time - last_request_time >= 10000) {
368 last_request_time = current_time;
369
370 // Cycle through 4 different approaches
371 if (approach_counter % 4 == 0) {
372 test_promise_approach();
373 FL_WARN("CYCLE: Demonstrated Promise-based pattern (Green LEDs on success)");
374 } else if (approach_counter % 4 == 1) {
375 test_await_approach();
376 FL_WARN("CYCLE: Demonstrated Await-based pattern (Blue LEDs on success)");
377 } else if (approach_counter % 4 == 2) {
378 test_json_response();
379 FL_WARN("CYCLE: Demonstrated JSON Promise pattern (Blue LEDs on success)");
380 } else if (approach_counter % 4 == 3) {
381 test_json_await();
382 FL_WARN("CYCLE: Demonstrated JSON Await pattern (Cyan LEDs on success)");
383 }
384
385 approach_counter++;
386
387 FL_WARN("NEXT: Will switch to next approach in 10 seconds...");
388 }
389
390 // TUTORIAL NOTE: Async operations are automatically managed!
391 // * On WASM: delay() pumps async tasks every 1ms automatically
392 // * On all platforms: FastLED.show() triggers async updates via engine events
393 // * No manual async updates needed - everything happens behind the scenes!
394
395
396 // TUTORIAL: This delay automatically pumps async tasks on WASM!
397 // The delay is broken into 1ms chunks with async processing between chunks.
398 // This isn't necessary when calling the await approach, but is critical
399 // the standard promise.then() approach.
400 // Note: In the future loop() may become a macro to inject auto pumping
401 // of the async tasks.
402 delay(10);
403}

Callers

nothing calls this directly

Calls 6

test_promise_approachFunction · 0.85
test_await_approachFunction · 0.85
test_json_responseFunction · 0.85
test_json_awaitFunction · 0.85
millisFunction · 0.50
delayFunction · 0.50

Tested by

no test coverage detected