tryagain
is a crate to try things again if they fail inspired by
backoff that offers an easier way to cancel
retry attemps and uses a non-blocking async implementation.
tryagain
works with both tokio and
async-std through the use of the
feature flags runtime-tokio
and runtime-async-std
.
let counter = RefCell::new(0);
let fails_four_times = || {
let mut counter = counter.borrow_mut();
*counter += 1;
if *counter < 5 {
Err(*counter)
} else {
Ok(())
}
};
tryagain::retry(ImmediateBackoff, fails_four_times);
let counter = RefCell::new(0);
let fails_four_times = || async {
let mut counter = counter.borrow_mut();
*counter += 1;
if *counter < 5 {
Err(*counter)
} else {
Ok(())
}
};
tryagain::future::retry(ImmediateBackoff, fails_four_times).await;