From 1fb413fd8014ad5911a95292bcfbeadb5a58d72f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 21 Feb 2023 20:56:10 +0100 Subject: Change `subscription::run` to take a function pointer ... and rename the old `run` to `run_with_id`. --- native/src/subscription.rs | 17 +++++++++++++++-- 1 file 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(builder: fn() -> S) -> Subscription +where + S: Stream + 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(id: I, stream: S) -> Subscription +pub fn run_with_id(id: I, stream: S) -> Subscription where I: Hash + 'static, S: Stream + 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), -- cgit