Skip to content

Commit

Permalink
Update spawn_blinking_led_task()
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Jan 17, 2024
1 parent e7d5e47 commit b63519c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/output/blinking_led_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlinkingLedOutput> {
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
Expand Down

0 comments on commit b63519c

Please sign in to comment.