https://github.com/zebp/tryagain
A library to try things again if they fail
https://github.com/zebp/tryagain
crate rust
Last synced: about 2 months ago
JSON representation
A library to try things again if they fail
- Host: GitHub
- URL: https://github.com/zebp/tryagain
- Owner: zebp
- License: unlicense
- Created: 2021-01-22T18:37:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-16T23:25:36.000Z (over 3 years ago)
- Last Synced: 2025-04-02T05:49:36.374Z (about 2 months ago)
- Topics: crate, rust
- Language: Rust
- Homepage: https://docs.rs/tryagain
- Size: 15.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tryagain
[![Docs.rs][docs-badge]][docs-url]
[![Crates.io][crates-badge]][crates-url]
[![Unlicense][license-badge]][license-url][crates-badge]: https://img.shields.io/crates/v/tryagain.svg
[crates-url]: https://crates.io/crates/tryagain
[license-badge]: https://img.shields.io/badge/license-Unlicense-blue.svg
[license-url]: https://github.com/vlakreeh/tryagain/blob/master/LICENSE
[docs-badge]: https://img.shields.io/badge/docs.rs-rustdoc-green
[docs-url]: https://docs.rs/tryagain/`tryagain` is a crate to try things again if they fail inspired by
[backoff](https://docs.rs/backoff) that offers an easier way to cancel
retry attemps and uses a non-blocking async implementation.
`tryagain` works with both [tokio](https://crates.io/crates/tokio) and
[async-std](https://crates.io/crates/async-std) through the use of the
feature flags `runtime-tokio` and `runtime-async-std`.## Sync example
```rust
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);
```
## Async example
```rust
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;
```