Skip to content

Commit 713b6d7

Browse files
committed
ref: try_operation_with_failover
1 parent cae3cc8 commit 713b6d7

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/robust_provider/provider.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use alloy::{
99
transports::{RpcError, TransportErrorKind},
1010
};
1111
use backon::{ExponentialBuilder, Retryable};
12+
use futures::TryFutureExt;
1213
use thiserror::Error;
1314
use tokio::time::{error as TokioError, timeout};
1415
use tracing::{error, info};
@@ -323,15 +324,11 @@ impl<N: Network> RobustProvider<N> {
323324
Fut: Future<Output = Result<T, RpcError<TransportErrorKind>>>,
324325
{
325326
let primary = self.primary();
326-
let result = self.try_provider_with_timeout(primary, &operation).await;
327-
328-
if result.is_ok() {
329-
return result;
330-
}
331-
332-
let last_error = result.unwrap_err();
333-
334-
self.try_fallback_providers(&operation, require_pubsub, last_error).await
327+
self.try_provider_with_timeout(primary, &operation)
328+
.or_else(|last_error| {
329+
self.try_fallback_providers(&operation, require_pubsub, last_error)
330+
})
331+
.await
335332
}
336333

337334
pub(crate) async fn try_fallback_providers<T: Debug, F, Fut>(

0 commit comments

Comments
 (0)