change
This commit is contained in:
+11
-13
@@ -115,8 +115,8 @@ fn main() -> Result<(), iced_layershell::Error> {
|
||||
}
|
||||
|
||||
fn gather_subscriptions(bar: &Bar) -> Subscription<Message> {
|
||||
// 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,20 +125,19 @@ fn gather_subscriptions(bar: &Bar) -> Subscription<Message> {
|
||||
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<Message>| async move {
|
||||
iced::stream::channel(
|
||||
0,
|
||||
|mut sender: iced::futures::channel::mpsc::Sender<Message>| 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)))
|
||||
.send(Message::Subscription(SubscriptionPayloadKind::Clock(
|
||||
payload,
|
||||
)))
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
@@ -146,7 +145,8 @@ fn gather_subscriptions(bar: &Bar) -> Subscription<Message> {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -174,9 +174,7 @@ fn update(bar: &mut Bar, msg: Message) -> Task<Message> {
|
||||
.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)),
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user