diff options
author | 2019-12-08 08:21:26 +0100 | |
---|---|---|
committer | 2019-12-08 08:21:26 +0100 | |
commit | 98160406f714728afe718f305bf9d12be1676b2d (patch) | |
tree | bf8fec3cb66bc478a021aba156d6be580586616e /examples | |
parent | 9b84b6e40336543380312aa1b2b1091791ec25cd (diff) | |
download | iced-98160406f714728afe718f305bf9d12be1676b2d.tar.gz iced-98160406f714728afe718f305bf9d12be1676b2d.tar.bz2 iced-98160406f714728afe718f305bf9d12be1676b2d.zip |
Allow listening to runtime events in subscriptions
Diffstat (limited to '')
-rw-r--r-- | examples/clock.rs | 20 |
1 files changed, 9 insertions, 11 deletions
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<Message> iced::subscription::Handle for Tick<Message> + impl<Message> iced_native::subscription::Connection for Tick<Message> 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() } } } |