From b63519c705a7b84de45388c591925c63a48a2e14 Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Wed, 17 Jan 2024 18:26:43 +0100 Subject: [PATCH] Update spawn_blinking_led_task() --- src/output/blinking_led_task.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/output/blinking_led_task.rs b/src/output/blinking_led_task.rs index 2c2e5b2..351fe5a 100644 --- a/src/output/blinking_led_task.rs +++ b/src/output/blinking_led_task.rs @@ -24,11 +24,19 @@ pub fn blinking_led_task( } } +/// Spawn a task that periodically emits a blinking LED trigger. +/// +/// Needed to synchronize the frequencies of all blinking LEDs. +/// +/// Returns a subscriber for receiving update triggers. The initial +/// update is available immediately and emitted as a change notification. #[cfg(feature = "blinking-led-task-tokio-rt")] #[must_use] pub fn spawn_blinking_led_task(period: Duration) -> discro::Subscriber { let publisher = Publisher::new(BlinkingLedOutput::ON); - let subscriber = publisher.subscribe(); + // Mark the subscriber as changed on subscription for emitting + // an initial change notification immediately. + let subscriber = publisher.subscribe_changed(); let task = blinking_led_task(period, publisher); tokio::spawn(task); subscriber