summaryrefslogtreecommitdiffstats
path: root/futures
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-04 03:28:47 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-04 03:28:47 +0100
commit6d46833eb2a068bd3655859ea828dad04293e5ba (patch)
tree42cbe1d9a65a2e03e63887611251ed8532f49872 /futures
parentf5186f31f1e5eed8fe20c5d6e62e2f531fee6365 (diff)
downloadiced-6d46833eb2a068bd3655859ea828dad04293e5ba.tar.gz
iced-6d46833eb2a068bd3655859ea828dad04293e5ba.tar.bz2
iced-6d46833eb2a068bd3655859ea828dad04293e5ba.zip
Support event subscriptions in `iced_web`
Also improves the overall web runtime, avoiding nested update loops.
Diffstat (limited to 'futures')
-rw-r--r--futures/src/runtime.rs20
-rw-r--r--futures/src/subscription/tracker.rs7
2 files changed, 11 insertions, 16 deletions
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,