pub trait ReconnectingStream{
// Provided methods
fn with_reconnect_backoff<St, InitError>(
self,
policy: ReconnectionBackoffPolicy,
stream_key: StreamKey,
) -> impl Stream<Item = St>
where Self: Stream<Item = Result<St, InitError>>,
St: Stream,
InitError: Debug { ... }
fn with_reconnect_backoff_reporting<St, InitError>(
self,
policy: ReconnectionBackoffPolicy,
stream_key: StreamKey,
) -> impl Stream<Item = Result<St, ReinitFailure<InitError>>>
where Self: Stream<Item = Result<St, InitError>>,
St: Stream,
InitError: Debug { ... }
fn with_termination_on_error<St, T, E, FnIsTerminal>(
self,
is_terminal: FnIsTerminal,
stream_key: StreamKey,
) -> impl Stream<Item = impl Stream<Item = Result<T, E>>>
where Self: Stream<Item = St>,
St: Stream<Item = Result<T, E>>,
FnIsTerminal: Fn(&E) -> bool + Copy { ... }
fn with_reconnection_events<St, Origin>(
self,
origin: Origin,
) -> impl Stream<Item = Event<Origin, St::Item>>
where Self: Stream<Item = St>,
St: Stream,
Origin: Clone + 'static { ... }
fn with_reconnection_events_reporting<St, InitError, Origin, FnOnFailure>(
self,
origin: Origin,
on_failure: FnOnFailure,
) -> impl Stream<Item = Event<Origin, St::Item>>
where Self: Stream<Item = Result<St, ReinitFailure<InitError>>>,
St: Stream,
Origin: Clone,
FnOnFailure: Fn(ReinitFailure<InitError>) -> St::Item { ... }
fn with_error_handler<FnOnErr, Origin, T, E>(
self,
op: FnOnErr,
) -> impl Stream<Item = Event<Origin, T>>
where Self: Stream<Item = Event<Origin, Result<T, E>>>,
FnOnErr: Fn(E) + 'static { ... }
fn forward_to<Transmitter>(
self,
tx: Transmitter,
) -> impl Future<Output = ()> + Send
where Self: Stream + Sized + Send,
Self::Item: Into<Transmitter::Item>,
Transmitter: Tx + Send + 'static { ... }
}Expand description
Utilities for handling a continually reconnecting Stream initialised via the
init_reconnecting_stream function.
Provided Methods§
Sourcefn with_reconnect_backoff<St, InitError>(
self,
policy: ReconnectionBackoffPolicy,
stream_key: StreamKey,
) -> impl Stream<Item = St>
fn with_reconnect_backoff<St, InitError>( self, policy: ReconnectionBackoffPolicy, stream_key: StreamKey, ) -> impl Stream<Item = St>
Add an exponential backoff policy to an initialised ReconnectingStream using the
provided ReconnectionBackoffPolicy.
A failed re-initialisation is logged with warn! and discarded. Use
with_reconnect_backoff_reporting to receive it.
Sourcefn with_reconnect_backoff_reporting<St, InitError>(
self,
policy: ReconnectionBackoffPolicy,
stream_key: StreamKey,
) -> impl Stream<Item = Result<St, ReinitFailure<InitError>>>
fn with_reconnect_backoff_reporting<St, InitError>( self, policy: ReconnectionBackoffPolicy, stream_key: StreamKey, ) -> impl Stream<Item = Result<St, ReinitFailure<InitError>>>
Add an exponential backoff policy to an initialised ReconnectingStream using the
provided ReconnectionBackoffPolicy, yielding each failed re-initialisation as a
ReinitFailure.
A failure is yielded as soon as it happens; the backoff then runs before the next attempt.
ReinitFailure::attempt counts consecutive failures, and resets when an attempt succeeds.
Sourcefn with_termination_on_error<St, T, E, FnIsTerminal>(
self,
is_terminal: FnIsTerminal,
stream_key: StreamKey,
) -> impl Stream<Item = impl Stream<Item = Result<T, E>>>
fn with_termination_on_error<St, T, E, FnIsTerminal>( self, is_terminal: FnIsTerminal, stream_key: StreamKey, ) -> impl Stream<Item = impl Stream<Item = Result<T, E>>>
Terminates the inner Stream if the encountered error is determined to be unrecoverable
by the provided closure. This will cause the ReconnectingStream to re-initialise the
inner Stream.
Sourcefn with_reconnection_events<St, Origin>(
self,
origin: Origin,
) -> impl Stream<Item = Event<Origin, St::Item>>
fn with_reconnection_events<St, Origin>( self, origin: Origin, ) -> impl Stream<Item = Event<Origin, St::Item>>
Maps every ReconnectingStream Stream::Item into an reconnect::Event::Item,
and chain a reconnect::Event::Reconnecting
Pairs with with_reconnect_backoff, which discards failed
re-initialisations. To report them as events, use
with_reconnect_backoff_reporting with
with_reconnection_events_reporting.
Sourcefn with_reconnection_events_reporting<St, InitError, Origin, FnOnFailure>(
self,
origin: Origin,
on_failure: FnOnFailure,
) -> impl Stream<Item = Event<Origin, St::Item>>where
Self: Stream<Item = Result<St, ReinitFailure<InitError>>>,
St: Stream,
Origin: Clone,
FnOnFailure: Fn(ReinitFailure<InitError>) -> St::Item,
fn with_reconnection_events_reporting<St, InitError, Origin, FnOnFailure>(
self,
origin: Origin,
on_failure: FnOnFailure,
) -> impl Stream<Item = Event<Origin, St::Item>>where
Self: Stream<Item = Result<St, ReinitFailure<InitError>>>,
St: Stream,
Origin: Clone,
FnOnFailure: Fn(ReinitFailure<InitError>) -> St::Item,
Maps the initialisation attempts yielded by
with_reconnect_backoff_reporting into
reconnect::Events.
Each initialised stream’s items become Event::Items, followed by one
Event::Reconnecting when it ends. Each failed attempt becomes the single
Event::Item that on_failure makes of it. A failed attempt ends no stream, so it adds
no further Event::Reconnecting.
Sourcefn with_error_handler<FnOnErr, Origin, T, E>(
self,
op: FnOnErr,
) -> impl Stream<Item = Event<Origin, T>>
fn with_error_handler<FnOnErr, Origin, T, E>( self, op: FnOnErr, ) -> impl Stream<Item = Event<Origin, T>>
Handles all encountered errors with the provided closure before filtering them out,
returning a Stream of the Ok values. Useful for logging recoverable errors before
continuing.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".