#timeout #future #callback #combinator #tokio #execute #allowing

inspect-timeout

A future combinator that applies a timeout with a custom callback when the timeout elapses

2 releases

0.1.1 Oct 1, 2024
0.1.0 Oct 1, 2024

#3 in #allowing

25 downloads per month

MIT/Apache

5KB
88 lines

inspect-timeout

inspect-timeout is a Rust library that provides a Future combinator, allowing you to apply a timeout with a custom callback that gets executed when the timeout elapses. It's useful when you need to handle cases where a Future doesn't complete within a specified time.

Features

  • Apply a timeout to any Future
  • Execute a custom function if the timeout expires

Example

use std::time::Duration;
use inspect_timeout::InspectTimeoutExt;

#[tokio::main]
async fn main() {
    tokio::time::sleep(Duration::from_secs(15))
        .inspect_timeout(Duration::from_secs(5), || println!("warning"))
        .await;
}

Dependencies

~2.3–8MB
~63K SLoC