Implement subscription::run 🎉
This commit is contained in:
parent
810b445f8d
commit
7442d0b66f
1 changed files with 19 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue