diff --git a/Cargo.toml b/Cargo.toml index c5ea0292..3eea0bb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,6 +106,7 @@ cosmic-config = { path = "cosmic-config" } cosmic-settings-daemon = { git = "https://github.com/pop-os/dbus-settings-bindings", optional = true } css-color = "0.2.5" derive_setters = "0.1.5" +futures = "0.3" image = { version = "0.25.5", default-features = false, features = [ "jpeg", "png", diff --git a/src/task.rs b/src/task.rs index a730b37e..35dcf4de 100644 --- a/src/task.rs +++ b/src/task.rs @@ -3,6 +3,7 @@ //! Create asynchronous actions to be performed in the background. +use futures::stream::{Stream, StreamExt}; use std::future::Future; /// Yields a task which contains a batch of tasks. @@ -23,3 +24,10 @@ pub fn future, Y: 'static>( pub fn message, Y: 'static>(message: X) -> iced::Task { future(async move { message.into() }) } + +/// Yields a task which will run a stream on the runtime executor. +pub fn stream + 'static, Y: 'static>( + stream: impl Stream + Send + 'static, +) -> iced::Task { + iced::Task::stream(stream.map(Into::into)) +}