From 6d46833eb2a068bd3655859ea828dad04293e5ba Mon Sep 17 00:00:00 2001
From: Héctor Ramón Jiménez <hector0193@gmail.com>
Date: Tue, 4 Feb 2020 03:28:47 +0100
Subject: Support event subscriptions in `iced_web`

Also improves the overall web runtime, avoiding nested update loops.
---
 futures/src/runtime.rs              | 20 ++++++++------------
 futures/src/subscription/tracker.rs |  7 +++----
 2 files changed, 11 insertions(+), 16 deletions(-)

(limited to 'futures')

diff --git a/futures/src/runtime.rs b/futures/src/runtime.rs
index 9fd9899a..3be45a26 100644
--- a/futures/src/runtime.rs
+++ b/futures/src/runtime.rs
@@ -1,7 +1,7 @@
 //! Run commands and keep track of subscriptions.
 use crate::{subscription, Command, Executor, Subscription};
 
-use futures::Sink;
+use futures::{channel::mpsc, Sink};
 use std::marker::PhantomData;
 
 /// A batteries-included runtime of commands and subscriptions.
@@ -27,11 +27,8 @@ where
     Hasher: std::hash::Hasher + Default,
     Event: Send + Clone + 'static,
     Executor: self::Executor,
-    Sender: Sink<Message, Error = core::convert::Infallible>
-        + Unpin
-        + Send
-        + Clone
-        + 'static,
+    Sender:
+        Sink<Message, Error = mpsc::SendError> + Unpin + Send + Clone + 'static,
     Message: Send + 'static,
 {
     /// Creates a new empty [`Runtime`].
@@ -76,12 +73,10 @@ where
         for future in futures {
             let mut sender = self.sender.clone();
 
-            self.executor.spawn(future.then(|message| {
-                async move {
-                    let _ = sender.send(message).await;
+            self.executor.spawn(future.then(|message| async move {
+                let _ = sender.send(message).await;
 
-                    ()
-                }
+                ()
             }));
         }
     }
@@ -112,7 +107,8 @@ where
     /// See [`Tracker::broadcast`] to learn more.
     ///
     /// [`Runtime`]: struct.Runtime.html
-    /// [`Tracker::broadcast`]: subscription/struct.Tracker.html#method.broadcast
+    /// [`Tracker::broadcast`]:
+    /// subscription/struct.Tracker.html#method.broadcast
     pub fn broadcast(&mut self, event: Event) {
         self.subscriptions.broadcast(event);
     }
diff --git a/futures/src/subscription/tracker.rs b/futures/src/subscription/tracker.rs
index c8a1ee18..cfa36170 100644
--- a/futures/src/subscription/tracker.rs
+++ b/futures/src/subscription/tracker.rs
@@ -1,8 +1,7 @@
 use crate::Subscription;
 
-use futures::{future::BoxFuture, sink::Sink};
-use std::collections::HashMap;
-use std::marker::PhantomData;
+use futures::{channel::mpsc, future::BoxFuture, sink::Sink};
+use std::{collections::HashMap, marker::PhantomData};
 
 /// A registry of subscription streams.
 ///
@@ -64,7 +63,7 @@ where
     where
         Message: 'static + Send,
         Receiver: 'static
-            + Sink<Message, Error = core::convert::Infallible>
+            + Sink<Message, Error = mpsc::SendError>
             + Unpin
             + Send
             + Clone,
-- 
cgit