From 77c3a8ed901dde64b695c0b4639830bae504b417 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Wed, 19 Mar 2025 04:04:30 +0100 Subject: [PATCH] feat(task): add stream function --- Cargo.toml | 1 + src/task.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index c5ea029..3eea0bb 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 a730b37..35dcf4d 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)) +}