diff options
| author | 2023-11-29 14:26:44 +0100 | |
|---|---|---|
| committer | 2023-11-29 14:26:44 +0100 | |
| commit | 7f8b17604a31e00becc43130ec516c1a53552c88 (patch) | |
| tree | b7cbc5ba003d61416d7959a6a704839b53822660 /futures | |
| parent | 7e7d65a23d864e4662c43028a41244ca30cac540 (diff) | |
| parent | a761448858521d11dc646e2ef5217e9e06628932 (diff) | |
| download | iced-7f8b17604a31e00becc43130ec516c1a53552c88.tar.gz iced-7f8b17604a31e00becc43130ec516c1a53552c88.tar.bz2 iced-7f8b17604a31e00becc43130ec516c1a53552c88.zip | |
Merge pull request #2150 from iced-rs/feature/command-run
`Stream` support for `Command`
Diffstat (limited to '')
| -rw-r--r-- | futures/src/runtime.rs | 25 | 
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 | 
