pub trait SupervisedStream: Send {
type Item: Send;
type ConnectError: Display + Send;
type StreamError: Display + Send;
type Stream: Stream<Item = Result<Self::Item, Self::StreamError>> + Send;
// Required methods
fn name(&self) -> &str;
fn backoff_policy(&self) -> BackoffPolicy;
fn connect<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream, Self::ConnectError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn on_message<'life0, 'async_trait>(
&'life0 mut self,
item: Self::Item,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn on_shutdown<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn supervise<'life0, 'async_trait, S>(
&'life0 mut self,
shutdown: S,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where S: Future<Output = ()> + Send + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
A supervised, self-reconnecting streaming subscription.
Implementors own the connection state (clients, channels, publishers) as
fields, so the reconnect/backoff/shutdown loop can hand each item to
on_message without the per-item state-cloning a
closure-based supervisor forces. The provided supervise
method owns that loop; an implementor supplies only how to connect, how to
handle an item, and (optionally) how to tear down.
Required Associated Types§
Sourcetype Item: Send
type Item: Send
Item the stream yields and on_message consumes.
Sourcetype ConnectError: Display + Send
type ConnectError: Display + Send
Error a failed connect attempt yields. Logged, then retried.
Sourcetype StreamError: Display + Send
type StreamError: Display + Send
Error the stream may yield per item. Logged, then reconnected.
Required Methods§
Sourcefn backoff_policy(&self) -> BackoffPolicy
fn backoff_policy(&self) -> BackoffPolicy
Backoff policy for reconnect attempts.
Sourcefn connect<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream, Self::ConnectError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn connect<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream, Self::ConnectError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Open a fresh stream of items.
Sourcefn on_message<'life0, 'async_trait>(
&'life0 mut self,
item: Self::Item,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_message<'life0, 'async_trait>(
&'life0 mut self,
item: Self::Item,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Handle one delivered item. Awaited to completion, so a slow handler holds the read loop; offload work that must not block it.
Provided Methods§
Sourcefn on_shutdown<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_shutdown<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Teardown run once before supervise returns, on every
exit path. Cancel tokens or release resources here.
Sourcefn supervise<'life0, 'async_trait, S>(
&'life0 mut self,
shutdown: S,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
fn supervise<'life0, 'async_trait, S>( &'life0 mut self, shutdown: S, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
Keep the subscription alive across reconnects until shutdown resolves.
Every item connect yields is handed to
on_message. Reconnect timing follows
BackoffPolicy: an opened stream that later closes or errors reconnects
at the floor, since the connection itself was healthy.
shutdown stops the supervisor promptly whenever it is waiting: to
connect, for the next item, or during a backoff. It does not interrupt an
in-flight on_message. on_shutdown runs on every
exit path.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".