diff options
author | 2023-02-21 21:18:01 +0100 | |
---|---|---|
committer | 2023-02-21 21:18:01 +0100 | |
commit | 666f3cd143047e49a010f0c97eabc7136f92aa35 (patch) | |
tree | ef1bd7cb5473c27f9b30ecdef317d507a99f84e2 /native | |
parent | 8c83d40e115a182136acfe013baa7a3f795ba3a5 (diff) | |
parent | 1fb413fd8014ad5911a95292bcfbeadb5a58d72f (diff) | |
download | iced-666f3cd143047e49a010f0c97eabc7136f92aa35.tar.gz iced-666f3cd143047e49a010f0c97eabc7136f92aa35.tar.bz2 iced-666f3cd143047e49a010f0c97eabc7136f92aa35.zip |
Merge pull request #1723 from iced-rs/subscription-run
Change `subscription::run` to take a function pointer
Diffstat (limited to 'native')
-rw-r--r-- | native/src/subscription.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/native/src/subscription.rs b/native/src/subscription.rs index b505f3cc..16e78e82 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -100,11 +100,24 @@ where }) } +/// Returns a [`Subscription`] that will call the given function to create and +/// asynchronously run the given [`Stream`]. +pub fn run<S, Message>(builder: fn() -> S) -> Subscription<Message> +where + S: Stream<Item = Message> + MaybeSend + 'static, + Message: 'static, +{ + Subscription::from_recipe(Runner { + id: builder, + spawn: move |_| builder(), + }) +} + /// Returns a [`Subscription`] that will create and asynchronously run the /// given [`Stream`]. /// /// The `id` will be used to uniquely identify the [`Subscription`]. -pub fn run<I, S, Message>(id: I, stream: S) -> Subscription<Message> +pub fn run_with_id<I, S, Message>(id: I, stream: S) -> Subscription<Message> where I: Hash + 'static, S: Stream<Item = Message> + MaybeSend + 'static, @@ -199,7 +212,7 @@ where use futures::future::{self, FutureExt}; use futures::stream::StreamExt; - run( + run_with_id( id, futures::stream::unfold(initial, move |state| f(state).map(Some)) .filter_map(future::ready), |