EmbarkStudios / EmbarkStudios/tryhard
Consider having current attempt number sent as a closure argument
- Dominant language
- Rust
- Stars
- 248
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
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 {
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:?}");
}
```
Contributor guide
Assessment
This issue has not been assessed yet.