From e2076612cb98d04a8a48add14d0068c2974d5653 Mon Sep 17 00:00:00 2001
From: Héctor Ramón Jiménez <hector0193@gmail.com>
Date: Thu, 30 Apr 2020 05:37:44 +0200
Subject: Implement `time::every` in `iced_futures`

---
 examples/stopwatch/src/main.rs | 44 ++++--------------------------------------
 1 file changed, 4 insertions(+), 40 deletions(-)

(limited to 'examples/stopwatch/src')

diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs
index 5a54ed2b..9de6d39e 100644
--- a/examples/stopwatch/src/main.rs
+++ b/examples/stopwatch/src/main.rs
@@ -1,6 +1,7 @@
 use iced::{
-    button, Align, Application, Button, Column, Command, Container, Element,
-    HorizontalAlignment, Length, Row, Settings, Subscription, Text,
+    button, executor, time, Align, Application, Button, Column, Command,
+    Container, Element, HorizontalAlignment, Length, Row, Settings,
+    Subscription, Text,
 };
 use std::time::{Duration, Instant};
 
@@ -28,7 +29,7 @@ enum Message {
 }
 
 impl Application for Stopwatch {
-    type Executor = iced_futures::executor::AsyncStd;
+    type Executor = executor::Default;
     type Message = Message;
     type Flags = ();
 
@@ -143,43 +144,6 @@ impl Application for Stopwatch {
     }
 }
 
-mod time {
-    use iced::futures;
-
-    pub fn every(
-        duration: std::time::Duration,
-    ) -> iced::Subscription<std::time::Instant> {
-        iced::Subscription::from_recipe(Every(duration))
-    }
-
-    struct Every(std::time::Duration);
-
-    impl<H, I> iced_native::subscription::Recipe<H, I> for Every
-    where
-        H: std::hash::Hasher,
-    {
-        type Output = std::time::Instant;
-
-        fn hash(&self, state: &mut H) {
-            use std::hash::Hash;
-
-            std::any::TypeId::of::<Self>().hash(state);
-            self.0.hash(state);
-        }
-
-        fn stream(
-            self: Box<Self>,
-            _input: futures::stream::BoxStream<'static, I>,
-        ) -> futures::stream::BoxStream<'static, Self::Output> {
-            use futures::stream::StreamExt;
-
-            async_std::stream::interval(self.0)
-                .map(|_| std::time::Instant::now())
-                .boxed()
-        }
-    }
-}
-
 mod style {
     use iced::{button, Background, Color, Vector};
 
-- 
cgit