diff --git a/src/docs/examples/inside_mut_self.md b/src/docs/examples/inside_mut_self.md new file mode 100644 index 0000000..3d6e8e8 --- /dev/null +++ b/src/docs/examples/inside_mut_self.md @@ -0,0 +1,23 @@ +Retry an async function inside `&mut self` functions. + +```rust + use anyhow::Result; + use backon::ExponentialBuilder; + use backon::Retryable; + + struct Test; + + impl Test { + async fn fetch(&self, url: &str) -> Result { + Ok(reqwest::get(url).await?.text().await?) + } + + async fn run(&mut self) -> Result { + let content = (|| async { self.fetch("https://www.rust-lang.org").await }) + .retry(ExponentialBuilder::default()) + .when(|e| e.to_string() == "retryable") + .await?; + Ok(content) + } + } +``` diff --git a/src/docs/examples/mod.rs b/src/docs/examples/mod.rs index e36f0b8..ff1b006 100644 --- a/src/docs/examples/mod.rs +++ b/src/docs/examples/mod.rs @@ -6,6 +6,9 @@ pub mod basic {} #[doc = include_str!("closure.md")] pub mod closure {} +#[doc = include_str!("inside_mut_self.md")] +pub mod inside_mut_self {} + #[doc = include_str!("sqlx.md")] pub mod sqlx {} diff --git a/src/docs/examples/with_self.md b/src/docs/examples/with_self.md index 9889b5b..67c2bde 100644 --- a/src/docs/examples/with_self.md +++ b/src/docs/examples/with_self.md @@ -13,6 +13,7 @@ Retry an async function which takes `&self` as receiver. } } + #[tokio::main(flavor = "current_thread")] async fn main() -> Result<()> { let test = Test;