diff options
author | 2022-01-14 19:43:54 +0700 | |
---|---|---|
committer | 2022-01-14 19:43:54 +0700 | |
commit | 7442d0b66f1c7b4c912ad5ac358dafcc8b07824e (patch) | |
tree | ee4fb78359897198498e4adf9a98fdc83c4be2bb /native | |
parent | 810b445f8d2f429e9ad07625f9b67dba09783d7a (diff) | |
download | iced-7442d0b66f1c7b4c912ad5ac358dafcc8b07824e.tar.gz iced-7442d0b66f1c7b4c912ad5ac358dafcc8b07824e.tar.bz2 iced-7442d0b66f1c7b4c912ad5ac358dafcc8b07824e.zip |
Implement `subscription::run` :tada:
Diffstat (limited to 'native')
-rw-r--r-- | native/src/subscription.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/native/src/subscription.rs b/native/src/subscription.rs index 7a1c5852..420797d1 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -84,6 +84,25 @@ where }) } +/// Returns a [`Subscription`] that will create and asynchronously run the +/// [`Stream`] returned by the provided closure. +/// +/// The `initial` state will be used to uniquely identify the [`Subscription`]. +pub fn run<T, S, Message>( + initial: T, + f: impl FnOnce(T) -> S + 'static, +) -> Subscription<Message> +where + Message: 'static, + T: Clone + Hash + 'static, + S: Stream<Item = Message> + Send + 'static, +{ + Subscription::from_recipe(Runner { + initial, + spawn: move |initial, _| f(initial), + }) +} + struct Runner<T, F, S, Message> where F: FnOnce(T, EventStream) -> S, |