From 98160406f714728afe718f305bf9d12be1676b2d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 8 Dec 2019 08:21:26 +0100 Subject: Allow listening to runtime events in subscriptions --- examples/clock.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'examples/clock.rs') diff --git a/examples/clock.rs b/examples/clock.rs index 5a404bfa..f06762bd 100644 --- a/examples/clock.rs +++ b/examples/clock.rs @@ -4,6 +4,8 @@ use iced::{ }; pub fn main() { + env_logger::init(); + Clock::run(Settings::default()) } @@ -108,30 +110,26 @@ mod time { >, } - impl iced::subscription::Handle for Tick + impl iced_native::subscription::Connection for Tick where Message: 'static, { + type Input = iced_native::subscription::Input; type Output = Message; fn id(&self) -> u64 { 0 } - fn stream(&self) -> futures::stream::BoxStream<'static, Message> { + fn stream( + &self, + input: iced_native::subscription::Input, + ) -> futures::stream::BoxStream<'static, Message> { use futures::StreamExt; - let duration = self.duration.clone(); let function = self.message.clone(); - let stream = - futures::stream::iter(std::iter::repeat(())).map(move |_| { - std::thread::sleep(duration); - - function(chrono::Local::now()) - }); - - stream.boxed() + input.map(move |_| function(chrono::Local::now())).boxed() } } } -- cgit