1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! backon intends to provide an opposite backoff implementation of the popular [backoff](https://docs.rs/backoff).
//!
//! - Newer: developed by Rust edition 2021 and latest stable.
//! - Cleaner: Iterator based abstraction, easy to use, customization friendly.
//! - Easier: Trait based implementations, works like a native function provided by closures.
//!
//! # Backoff
//!
//! Any types that implements `Iterator<Item = Duration>` can be used as backoff.
//!
//! backon also provides backoff implementations with reasonable defaults:
//!
//! - [`ConstantBackoff`]: backoff with constant delay and limited times.
//! - [`ExponentialBackoff`]: backoff with exponential delay, also provides jitter supports.
//!
//! # Examples
//!
//! Retry with default settings.
//!
//! ```no_run
//! use anyhow::Result;
//! use backon::ExponentialBuilder;
//! use backon::Retryable;
//!
//! async fn fetch() -> Result<String> {
//! Ok(reqwest::get("https://www.rust-lang.org")
//! .await?
//! .text()
//! .await?)
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let content = fetch.retry(&ExponentialBuilder::default()).await?;
//!
//! println!("fetch succeeded: {}", content);
//! Ok(())
//! }
//! ```
//!
//! Retry with specify retryable error.
//!
//! ```no_run
//! use anyhow::Result;
//! use backon::ExponentialBuilder;
//! use backon::Retryable;
//!
//! async fn fetch() -> Result<String> {
//! Ok(reqwest::get("https://www.rust-lang.org")
//! .await?
//! .text()
//! .await?)
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let content = fetch
//! .retry(&ExponentialBuilder::default())
//! .when(|e| e.to_string() == "retryable")
//! .await?;
//!
//! println!("fetch succeeded: {}", content);
//! Ok(())
//! }
//! ```
pub use Backoff;
pub use BackoffBuilder;
pub use ConstantBackoff;
pub use ConstantBuilder;
pub use ExponentialBackoff;
pub use ExponentialBuilder;
pub use Retry;
pub use Retryable;
pub use BlockingRetry;
pub use BlockingRetryable;