@@ -3,14 +3,16 @@ use crate::core::widget;
3
3
use crate :: futures:: futures:: channel:: mpsc;
4
4
use crate :: futures:: futures:: channel:: oneshot;
5
5
use crate :: futures:: futures:: future:: { self , FutureExt } ;
6
- use crate :: futures:: futures:: never:: Never ;
7
6
use crate :: futures:: futures:: stream:: { self , Stream , StreamExt } ;
8
7
use crate :: futures:: { boxed_stream, BoxStream , MaybeSend } ;
9
8
use crate :: Action ;
10
9
11
10
use std:: future:: Future ;
12
11
use std:: sync:: Arc ;
13
12
13
+ #[ doc( no_inline) ]
14
+ pub use sipper:: { sipper, stream, Never , Sender , Sipper , Straw } ;
15
+
14
16
/// A set of concurrent actions to be performed by the iced runtime.
15
17
///
16
18
/// A [`Task`] _may_ produce a bunch of values of type `T`.
@@ -57,6 +59,25 @@ impl<T> Task<T> {
57
59
Self :: stream ( stream. map ( f) )
58
60
}
59
61
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
+
60
81
/// Combines the given tasks and produces a single [`Task`] that will run all of them
61
82
/// in parallel.
62
83
pub fn batch ( tasks : impl IntoIterator < Item = Self > ) -> Self
0 commit comments