futures-retry

[Release docs]

[Master docs]

A simple crate that helps you to retry your Futures and Streams in a neat and simple way.

```rust extern crate futuresretry; // ... use futuresretry::{RetryPolicy, StreamRetryExt};

fn handleerror(e: io::Error) -> RetryPolicy { match e.kind() { io::ErrorKind::Interrupted => RetryPolicy::Repeat, io::ErrorKind::PermissionDenied => RetryPolicy::ForwardError(e), _ => RetryPolicy::WaitRetry(Duration::frommillis(5)), } }

// Use Box<...> instead of impl ... if your rust version doesn't support impl Trait. fn serve_connection(stream: TcpStream) -> impl Future

fn main() { let listener: TcpListener = // ... let server = listener.incoming() .intoretry(handleerror) // Magic happens here .andthen(|stream| { tokio::spawn(serveconnection(stream)); Ok(()) }) .foreach(|| Ok(())) .map_err(|e| eprintln!("Caught an error {}", e)); tokio::run(server); } ```

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.