@@ -3,14 +3,16 @@ use crate::core::widget;
33use crate :: futures:: futures:: channel:: mpsc;
44use crate :: futures:: futures:: channel:: oneshot;
55use crate :: futures:: futures:: future:: { self , FutureExt } ;
6- use crate :: futures:: futures:: never:: Never ;
76use crate :: futures:: futures:: stream:: { self , Stream , StreamExt } ;
87use crate :: futures:: { boxed_stream, BoxStream , MaybeSend } ;
98use crate :: Action ;
109
1110use std:: future:: Future ;
1211use std:: sync:: Arc ;
1312
13+ #[ doc( no_inline) ]
14+ pub use sipper:: { sipper, stream, Never , Sender , Sipper , Straw } ;
15+
1416/// A set of concurrent actions to be performed by the iced runtime.
1517///
1618/// A [`Task`] _may_ produce a bunch of values of type `T`.
@@ -57,6 +59,25 @@ impl<T> Task<T> {
5759 Self :: stream ( stream. map ( f) )
5860 }
5961
62+ /// Creates a [`Task`] that runs the given [`Sipper`] to completion, mapping
63+ /// progress with the first closure and the output with the second one.
64+ pub fn sip < S , Output , Progress > (
65+ sipper : S ,
66+ on_progress : impl Fn ( Progress ) -> T + MaybeSend + ' static ,
67+ on_output : impl FnOnce ( Output ) -> T + MaybeSend + ' static ,
68+ ) -> Self
69+ where
70+ S : Sipper < Output , Progress > + MaybeSend + ' static ,
71+ S :: Future : MaybeSend + ' static ,
72+ Output : MaybeSend ,
73+ Progress : MaybeSend ,
74+ T : MaybeSend + ' static ,
75+ {
76+ Self :: stream ( stream ( sipper:: sipper ( move |sender| async move {
77+ on_output ( sipper. map ( on_progress) . run ( sender) . await )
78+ } ) ) )
79+ }
80+
6081 /// Combines the given tasks and produces a single [`Task`] that will run all of them
6182 /// in parallel.
6283 pub fn batch ( tasks : impl IntoIterator < Item = Self > ) -> Self
0 commit comments