macro_rules! retry {
($e:expr) => { ... };
}Expand description
Retries a given expression a specified number of times with exponential backoff.
This macro attempts to execute the provided expression up to N times, where N
is the value set by set_retries. If the expression returns Ok, it returns the value.
If the expression returns Err, it logs a warning and retries after a delay that increases
exponentially with each retry.
The delay between retries is calculated as 1 * retry_cnt.pow(2) seconds, where retry_cnt
is the current retry attempt.
This macro supports both asynchronous and synchronous contexts:
- For
tokiousers, it usestokio::time::sleep. - For
async-stdusers, it usesasync_std::task::sleep. - For synchronous contexts, it uses
std::thread::sleep.
§Features
with-tokio: Usestokio::time::sleepfor async retries.with-async-std: Usesasync_std::task::sleepfor async retries.sync: Usesstd::thread::sleepfor sync retries.
§Errors
If all retry attempts fail, the last error is returned.