pub struct RobustSubscription<N: Network> { /* private fields */ }Expand description
A robust subscription wrapper that automatically handles provider failover and periodic reconnection attempts to the primary provider.
Implementations§
Source§impl<N: Network> RobustSubscription<N>
impl<N: Network> RobustSubscription<N>
Sourcepub async fn recv(&mut self) -> Result<N::HeaderResponse, Error>
pub async fn recv(&mut self) -> Result<N::HeaderResponse, Error>
Receive the next item from the subscription with automatic failover.
This method will:
- Attempt to receive from the current subscription (WebSocket or HTTP polling)
- Handle errors by switching to fallback providers
- Periodically attempt to reconnect to the primary provider
- Will switch to fallback providers if subscription timeout is exhausted
§Primary Provider Reconnection
The primary provider is retried in two scenarios:
- Periodic reconnection: Every
reconnect_interval(default: 30 seconds) while on a fallback provider and successfully receiving blocks. Note: The actual reconnection attempt occurs when a new block is received, so if blocks arrive slower than the reconnect interval, reconnection will be delayed until the next block. - Fallback failure: Immediately when a fallback provider fails, before attempting the next fallback provider
§Errors
- Propagates any underlying subscription errors.
- If all providers have been exhausted and failed, returns the last attempt’s error.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the subscription channel is empty (no pending messages)
Sourcepub fn into_stream(self) -> RobustSubscriptionStream<N>
pub fn into_stream(self) -> RobustSubscriptionStream<N>
Convert the subscription into a stream.
Trait Implementations§
Source§impl<N: 'static + Clone + Send + Network> From<RobustSubscription<N>> for RobustSubscriptionStream<N>
impl<N: 'static + Clone + Send + Network> From<RobustSubscription<N>> for RobustSubscriptionStream<N>
Source§fn from(recv: RobustSubscription<N>) -> Self
fn from(recv: RobustSubscription<N>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<N> Freeze for RobustSubscription<N>
impl<N> !RefUnwindSafe for RobustSubscription<N>
impl<N> Send for RobustSubscription<N>
impl<N> Sync for RobustSubscription<N>
impl<N> Unpin for RobustSubscription<N>
impl<N> UnsafeUnpin for RobustSubscription<N>
impl<N> !UnwindSafe for RobustSubscription<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more