tower_async/util/backoff/
mod.rs

1//! This module contains generic [backoff] utilities to be used with the retry
2//! and limit layers.
3//!
4//! The [`Backoff`] trait is a generic way to represent backoffs that can use
5//! any timer type.
6//!
7//! [`ExponentialBackoffMaker`] implements the maker type for  
8//! [`ExponentialBackoff`] which implements the [`Backoff`] trait and provides
9//! a batteries included exponential backoff and jitter strategy.
10//!
11//! [backoff]: https://en.wikipedia.org/wiki/Exponential_backoff
12
13/// Trait used to construct [`Backoff`] trait implementors.
14pub trait MakeBackoff {
15    /// The backoff type produced by this maker.
16    type Backoff: Backoff;
17
18    /// Constructs a new backoff type.
19    fn make_backoff(&self) -> Self::Backoff;
20}
21
22/// A backoff trait where a single mutable reference represents a single
23/// backoff session. Implementors must also implement [`Clone`] which will
24/// reset the backoff back to the default state for the next session.
25pub trait Backoff {
26    /// Initiate the next backoff in the sequence.
27    fn next_backoff(&self) -> impl std::future::Future<Output = ()>;
28}
29
30#[cfg(feature = "util-tokio")]
31mod exponential;
32#[cfg(feature = "util-tokio")]
33pub use exponential::{ExponentialBackoff, ExponentialBackoffMaker};