summaryrefslogtreecommitdiffstats
path: root/futures/src/runtime.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-19 20:41:52 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-19 20:41:52 +0100
commit1781068e1c3a65551db1e832fdbaddba99124051 (patch)
tree60e0b3854cc0541712572fbb0e56f14435951ea9 /futures/src/runtime.rs
parent41dec5bd203ff5b1574a33a17d5f7358ae1beea2 (diff)
parent7ae7fcb89855002519bab752fd3686106ce448db (diff)
downloadiced-1781068e1c3a65551db1e832fdbaddba99124051.tar.gz
iced-1781068e1c3a65551db1e832fdbaddba99124051.tar.bz2
iced-1781068e1c3a65551db1e832fdbaddba99124051.zip
Merge branch 'master' into remove-vertex-indexing
Diffstat (limited to 'futures/src/runtime.rs')
-rw-r--r--futures/src/runtime.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/futures/src/runtime.rs b/futures/src/runtime.rs
index 16111b36..cac7b7e1 100644
--- a/futures/src/runtime.rs
+++ b/futures/src/runtime.rs
@@ -1,7 +1,7 @@
//! Run commands and keep track of subscriptions.
use crate::core::event::{self, Event};
use crate::subscription;
-use crate::{BoxFuture, Executor, MaybeSend};
+use crate::{BoxFuture, BoxStream, Executor, MaybeSend};
use futures::{channel::mpsc, Sink};
use std::marker::PhantomData;
@@ -69,6 +69,29 @@ where
self.executor.spawn(future);
}
+ /// Runs a [`Stream`] in the [`Runtime`] until completion.
+ ///
+ /// The resulting `Message`s will be forwarded to the `Sender` of the
+ /// [`Runtime`].
+ ///
+ /// [`Stream`]: BoxStream
+ pub fn run(&mut self, stream: BoxStream<Message>) {
+ use futures::{FutureExt, StreamExt};
+
+ let sender = self.sender.clone();
+ let future =
+ stream.map(Ok).forward(sender).map(|result| match result {
+ Ok(()) => (),
+ Err(error) => {
+ log::warn!(
+ "Stream could not run until completion: {error}"
+ );
+ }
+ });
+
+ self.executor.spawn(future);
+ }
+
/// Tracks a [`Subscription`] in the [`Runtime`].
///
/// It will spawn new streams or close old ones as necessary! See