Macro switchboard_solana::retry
source · macro_rules! retry { ($attempts:expr, $delay_ms:expr, $expr:expr) => { ... }; }
Expand description
Retry a given expression a specified number of times with a delay between each attempt.
§Arguments
attempts
- The number of attempts to make.delay_ms
- The delay in milliseconds between each attempt.expr
- The expression to be retried.
§Returns
Returns a Result
containing the value of the expression if it succeeds within the specified number of attempts,
or an error if it fails on all attempts.
§Examples
use switchboard_solana::retry;
// Retry a blockhash fetch 3 times with a delay of 500ms in between each failure
let blockhash = retry!(3, 500, rpc.get_latest_blockhash().await)
.await
.map_err(|e| SbError::SolanaBlockhashFetchError(Arc::new(e)))?;