summaryrefslogtreecommitdiffstats
path: root/runtime/src/task.rs
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/task.rs')
-rw-r--r--runtime/src/task.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/runtime/src/task.rs b/runtime/src/task.rs
index 22cfb63e..022483f7 100644
--- a/runtime/src/task.rs
+++ b/runtime/src/task.rs
@@ -3,7 +3,6 @@ use crate::core::widget;
use crate::futures::futures::channel::mpsc;
use crate::futures::futures::channel::oneshot;
use crate::futures::futures::future::{self, FutureExt};
-use crate::futures::futures::never::Never;
use crate::futures::futures::stream::{self, Stream, StreamExt};
use crate::futures::{boxed_stream, BoxStream, MaybeSend};
use crate::Action;
@@ -11,6 +10,9 @@ use crate::Action;
use std::future::Future;
use std::sync::Arc;
+#[doc(no_inline)]
+pub use sipper::{sipper, stream, Never, Sender, Sipper, Straw};
+
/// A set of concurrent actions to be performed by the iced runtime.
///
/// A [`Task`] _may_ produce a bunch of values of type `T`.
@@ -57,6 +59,22 @@ impl<T> Task<T> {
Self::stream(stream.map(f))
}
+ /// Creates a [`Task`] that runs the given [`Sipper`] to completion, mapping
+ /// progress with the first closure and the output with the second one.
+ pub fn sip<S>(
+ sipper: S,
+ on_progress: impl FnMut(S::Progress) -> T + MaybeSend + 'static,
+ on_output: impl FnOnce(<S as Future>::Output) -> T + MaybeSend + 'static,
+ ) -> Self
+ where
+ S: sipper::Core + MaybeSend + 'static,
+ T: MaybeSend + 'static,
+ {
+ Self::stream(stream(sipper::sipper(move |sender| async move {
+ on_output(sipper.with(on_progress).run(sender).await)
+ })))
+ }
+
/// Combines the given tasks and produces a single [`Task`] that will run all of them
/// in parallel.
pub fn batch(tasks: impl IntoIterator<Item = Self>) -> Self