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> {
|
fn gather_subscriptions(bar: &Bar) -> Subscription<Message> {
|
||||||
// Only spawn a runner if some module actually wants it. `bar` is passed
|
//TODO: Get a vec of subscription enum 'bar_wants' and spawn a batch depending on what the
|
||||||
// precisely so we can check routes and avoid idle tickers.
|
//modules want.
|
||||||
let wants_clock = bar
|
let wants_clock = bar
|
||||||
.routes
|
.routes
|
||||||
.values()
|
.values()
|
||||||
@@ -125,20 +125,19 @@ fn gather_subscriptions(bar: &Bar) -> Subscription<Message> {
|
|||||||
return Subscription::none();
|
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((), |_| {
|
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 clock = ClockTicker::new();
|
||||||
let mut interval = tokio::time::interval(std::time::Duration::from_secs(1));
|
let mut interval = tokio::time::interval(std::time::Duration::from_secs(1));
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
for payload in clock.tick() {
|
for payload in clock.tick() {
|
||||||
if sender
|
if sender
|
||||||
.send(Message::Subscription(SubscriptionPayloadKind::Clock(payload)))
|
.send(Message::Subscription(SubscriptionPayloadKind::Clock(
|
||||||
|
payload,
|
||||||
|
)))
|
||||||
.await
|
.await
|
||||||
.is_err()
|
.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)
|
.get(*id)
|
||||||
.is_some_and(|kinds| kinds.contains(&ModuleSub::Clock(payload.kind)))
|
.is_some_and(|kinds| kinds.contains(&ModuleSub::Clock(payload.kind)))
|
||||||
})
|
})
|
||||||
.map(|(_, module)| {
|
.map(|(_, module)| module.update(ModuleMsg::new(module.id(), payload.clone())))
|
||||||
module.update(ModuleMsg::new(module.id(), payload.clone()))
|
|
||||||
})
|
|
||||||
.fold(Task::none(), |acc, t| acc.chain(t)),
|
.fold(Task::none(), |acc, t| acc.chain(t)),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user