sse banner

A Simple and unaltered retry crate for both sync and async Rust

Getting started

Sync

[dependencies]
retriable = "0.1.0"
./info

Both the return type and error type are unaltered from the original function

use retriable::retry::Retry;
use std::time::Duration;

let max_retries = 3;
let back_off = Duration::from_secs(3);
let retry = Retry::new(max_retries, back_off);

match retry
    .this(|| -> Result<&str, ()> { Ok("my unique error") }) {
        Ok(result) => {
            // handle the result of your function
        },
        Err(err) => {
            // handle the error
        }
    }

Async

[dependencies]
retriable = { version = "0.1.0", features = ["async"] }
use retriable::retry::Retry;
use std::time::Duration;

let max_retries = 3;
let back_off = Duration::from_secs(3);
let retry = Retry::new(max_retries, back_off);

match retry
    .this_async(async || -> Result<&str, ()> { Ok("my unique error") }).await {
        Ok(result) => {
            // handle the result of your function
        },
        Err(err) => {
            // handle the error
        }
    }