feat(task): add stream function

This commit is contained in:
Michael Aaron Murphy 2025-03-19 04:04:30 +01:00
parent cb6ea4c7c3
commit 77c3a8ed90
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
2 changed files with 9 additions and 0 deletions

View file

@ -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",

View file

@ -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<X: Into<Y>, Y: 'static>(
pub fn message<X: Send + 'static + Into<Y>, Y: 'static>(message: X) -> iced::Task<Y> {
future(async move { message.into() })
}
/// Yields a task which will run a stream on the runtime executor.
pub fn stream<X: Into<Y> + 'static, Y: 'static>(
stream: impl Stream<Item = X> + Send + 'static,
) -> iced::Task<Y> {
iced::Task::stream(stream.map(Into::into))
}