macro_rules! blocking_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. This will block the current thread until a value is resolved or the maximum number of attempts is reached.
§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::blocking_retry;
// Retry a blockhash fetch 3 times with a delay of 500ms in between each failure
let blockhash = blocking_retry!(3, 500, rpc.get_latest_blockhash())
.map_err(|e| OnDemandError::SolanaBlockhashFetchError(Arc::new(e)))?;