Allow listening to runtime events in subscriptions

This commit is contained in:
Héctor Ramón Jiménez 2019-12-08 08:21:26 +01:00
parent 9b84b6e403
commit 98160406f7
7 changed files with 89 additions and 40 deletions

View file

@ -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()
}
}
}