Trait google_cloud_bigquery::query::Retryable
source · pub trait Retryable<B, T, E, Fut, FutureFn>where
B: BackoffBuilder,
Fut: Future<Output = Result<T, E>>,
FutureFn: FnMut() -> Fut,{
// Required method
fn retry(
self,
builder: &B
) -> Retry<<B as BackoffBuilder>::Backoff, T, E, Fut, FutureFn, fn(_: &E) -> bool, fn(_: &E, _: Duration)> ⓘ;
}Expand description
Retryable will add retry support for functions that produces a futures with results.
That means all types that implement FnMut() -> impl Future<Output = Result<T, E>>
will be able to use retry.
For example:
- Functions without extra args:
ⓘ
async fn fetch() -> Result<String> {
Ok(reqwest::get("https://www.rust-lang.org").await?.text().await?)
}- Closures
ⓘ
|| async {
let x = reqwest::get("https://www.rust-lang.org")
.await?
.text()
.await?;
Err(anyhow::anyhow!(x))
}Example
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(())
}