diff --git a/src/main.rs b/src/main.rs index 76a90b9..b2304d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -115,8 +115,8 @@ fn main() -> Result<(), iced_layershell::Error> { } fn gather_subscriptions(bar: &Bar) -> Subscription { - // Only spawn a runner if some module actually wants it. `bar` is passed - // precisely so we can check routes and avoid idle tickers. + //TODO: Get a vec of subscription enum 'bar_wants' and spawn a batch depending on what the + //modules want. let wants_clock = bar .routes .values() @@ -125,28 +125,28 @@ fn gather_subscriptions(bar: &Bar) -> Subscription { return Subscription::none(); } - // A single 1s clock stream drives ALL modules that want a clock kind. - // The stream emits a `SubscriptionMsg` with kind+payload; `update` fans - // out to every module in `routes` that wants that kind. - // The builder must be non-capturing (fn pointer), so the Clock state - // lives inside the stream body; identity `()` keeps it alive forever. Subscription::run_with((), |_| { - iced::stream::channel(0, |mut sender: iced::futures::channel::mpsc::Sender| async move { - let mut clock = ClockTicker::new(); - let mut interval = tokio::time::interval(std::time::Duration::from_secs(1)); - loop { - interval.tick().await; - for payload in clock.tick() { - if sender - .send(Message::Subscription(SubscriptionPayloadKind::Clock(payload))) - .await - .is_err() - { - return; + iced::stream::channel( + 0, + |mut sender: iced::futures::channel::mpsc::Sender| async move { + let mut clock = ClockTicker::new(); + let mut interval = tokio::time::interval(std::time::Duration::from_secs(1)); + loop { + interval.tick().await; + for payload in clock.tick() { + if sender + .send(Message::Subscription(SubscriptionPayloadKind::Clock( + payload, + ))) + .await + .is_err() + { + return; + } } } - } - }) + }, + ) }) } @@ -174,9 +174,7 @@ fn update(bar: &mut Bar, msg: Message) -> Task { .get(*id) .is_some_and(|kinds| kinds.contains(&ModuleSub::Clock(payload.kind))) }) - .map(|(_, module)| { - module.update(ModuleMsg::new(module.id(), payload.clone())) - }) + .map(|(_, module)| module.update(ModuleMsg::new(module.id(), payload.clone()))) .fold(Task::none(), |acc, t| acc.chain(t)), },