generated from EmbarkStudios/opensource-template
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Is your feature request related to a problem? Please describe.
Sometimes you want to know what is going on and more detailed logs can be useful
Describe the solution you'd like
A current attempt passed as a closure argument:
tryhard::retry_fn(|n| ...)
Describe alternatives you've considered
Of course you can always have let mut attempt = 0, but it is not really idiomatic, is it? :)
Additional context
Illustrative example:
use tryhard; // 0.5.0
use std::time::Duration;
async fn call(n: u8) -> Result<String, String> {
if n > 5 {
Ok("Ok, move along".to_string())
}else {
Err("You shall not pass".to_string())
}
}
#[tokio::main]
async fn main() {
let mut attempt = 0;
let s = tryhard::retry_fn(|| async {
attempt += 1;
println!("Once more into the fray, attempt: {attempt}");
call(attempt).await
})
.retries(6)
.exponential_backoff(Duration::from_secs(1))
.max_delay(Duration::from_secs(10))
.await;
println!("{s:?}");
}
nickpresta and said1296
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request