pub struct RobustProviderBuilder<N: Network, P: IntoRootProvider<N>> { /* private fields */ }Expand description
Builder for constructing a RobustProvider.
Use this to configure timeouts, retry/backoff, and one or more fallback providers.
Implementations§
Source§impl<N: Network, P: IntoRootProvider<N>> RobustProviderBuilder<N, P>
impl<N: Network, P: IntoRootProvider<N>> RobustProviderBuilder<N, P>
Sourcepub fn new(provider: P) -> Self
pub fn new(provider: P) -> Self
Create a new RobustProvider with default settings.
The provided provider is treated as the primary provider.
Any type implementing IntoRootProvider can be used.
Sourcepub fn fragile(provider: P) -> Self
pub fn fragile(provider: P) -> Self
Create a new RobustProvider with no retry attempts and only timeout set.
The provided provider is treated as the primary provider.
Sourcepub fn fallback<F: IntoRootProvider<N> + Send + 'static>(
self,
provider: F,
) -> Self
pub fn fallback<F: IntoRootProvider<N> + Send + 'static>( self, provider: F, ) -> Self
Add a fallback provider to the list.
Fallback providers are used when the primary provider times out or fails.
Sourcepub fn call_timeout(self, timeout: Duration) -> Self
pub fn call_timeout(self, timeout: Duration) -> Self
Set the maximum timeout for RPC operations.
Sourcepub fn subscription_timeout(self, timeout: Duration) -> Self
pub fn subscription_timeout(self, timeout: Duration) -> Self
Set the timeout for subscription operations.
This should be set higher than call_timeout to accommodate chains
with slow block times. Default is DEFAULT_SUBSCRIPTION_TIMEOUT.
Sourcepub fn subscription_buffer_capacity(self, buffer_capacity: usize) -> Self
pub fn subscription_buffer_capacity(self, buffer_capacity: usize) -> Self
Set the subscription stream buffer capacity.
Controls the buffer capacity for subscription streams. If new blocks arrive while the stream buffer is full, a lagged error will be emitted, indicating that stream items were dropped due to the consumer not keeping pace with the stream.
Default is DEFAULT_SUBSCRIPTION_BUFFER_CAPACITY.
Sourcepub fn max_retries(self, max_retries: usize) -> Self
pub fn max_retries(self, max_retries: usize) -> Self
Set the maximum number of retry attempts.
Sourcepub fn min_delay(self, min_delay: Duration) -> Self
pub fn min_delay(self, min_delay: Duration) -> Self
Set the base delay for exponential backoff retries.
Sourcepub fn reconnect_interval(self, reconnect_interval: Duration) -> Self
pub fn reconnect_interval(self, reconnect_interval: Duration) -> Self
Set the interval for attempting to reconnect to the primary provider.
After a failover to a fallback provider, the subscription will periodically
attempt to reconnect to the primary provider at this interval.
Default is DEFAULT_RECONNECT_INTERVAL.
Sourcepub async fn build(self) -> Result<RobustProvider<N>, Error>
pub async fn build(self) -> Result<RobustProvider<N>, Error>
Build the RobustProvider.
Final builder method: consumes the builder and returns the built RobustProvider.
§Errors
Returns an error if any of the providers fail to connect.
Auto Trait Implementations§
impl<N, P> Freeze for RobustProviderBuilder<N, P>where
P: Freeze,
impl<N, P> !RefUnwindSafe for RobustProviderBuilder<N, P>
impl<N, P> Send for RobustProviderBuilder<N, P>where
P: Send,
impl<N, P> !Sync for RobustProviderBuilder<N, P>
impl<N, P> Unpin for RobustProviderBuilder<N, P>where
P: Unpin,
impl<N, P> !UnwindSafe for RobustProviderBuilder<N, P>
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
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>
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>
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