pub trait SubscribeExt<T>: Stream<Item = T> + Sized {
// Required method
fn subscribe<'async_trait, F, Fut, E, OnError>(
self,
on_next_func: F,
on_error_callback: OnError,
cancellation_token: Option<CancellationToken>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where F: Fn(T, CancellationToken) -> Fut + Clone + Send + Sync + 'static + 'async_trait,
Fut: Future<Output = Result<(), E>> + Send + Sync + 'static + 'async_trait,
OnError: Fn(E) + Clone + Send + Sync + 'static + 'async_trait,
T: Debug + Clone + Send + Sync + 'static,
E: Send + Sync + 'static + 'async_trait,
Self: 'async_trait;
}Expand description
Extension trait providing async subscription capabilities for streams.
This trait enables processing stream items with async handlers in a sequential manner.
Required Methods§
Sourcefn subscribe<'async_trait, F, Fut, E, OnError>(
self,
on_next_func: F,
on_error_callback: OnError,
cancellation_token: Option<CancellationToken>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
F: Fn(T, CancellationToken) -> Fut + Clone + Send + Sync + 'static + 'async_trait,
Fut: Future<Output = Result<(), E>> + Send + Sync + 'static + 'async_trait,
OnError: Fn(E) + Clone + Send + Sync + 'static + 'async_trait,
T: Debug + Clone + Send + Sync + 'static,
E: Send + Sync + 'static + 'async_trait,
Self: 'async_trait,
fn subscribe<'async_trait, F, Fut, E, OnError>(
self,
on_next_func: F,
on_error_callback: OnError,
cancellation_token: Option<CancellationToken>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
F: Fn(T, CancellationToken) -> Fut + Clone + Send + Sync + 'static + 'async_trait,
Fut: Future<Output = Result<(), E>> + Send + Sync + 'static + 'async_trait,
OnError: Fn(E) + Clone + Send + Sync + 'static + 'async_trait,
T: Debug + Clone + Send + Sync + 'static,
E: Send + Sync + 'static + 'async_trait,
Self: 'async_trait,
Subscribes to the stream with an async handler, processing items sequentially.
This method consumes the stream and processes each item with the provided handler. Items are processed in the order they arrive, with each item’s handler completing before the next item is processed.
§Behavior
- Processes each stream item with the provided async handler sequentially
- Waits for handler completion before processing next item
- Continues until stream ends or cancellation token is triggered
- Errors from handlers are passed to the error callback
§Arguments
on_next_func- Async function called for each stream itemon_error_callback- Error handler called when handler returns an errorcancellation_token- Optional token to stop processing
§See Also
subscribe_latest- Cancels old work for new items
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.