async_timeouts/
lib.rs

1// Copyright 2024 Artyom Sinyugin
2
3//! # Async Timeouts Helper
4//! It is a simple instrument to delay execution of an async task with the possibility
5//! to stop timer or reset it with another time value. 
6//! 
7//! It is convinient to use this crate with [Notify] or different 
8//! channels (i.e. [async_channel]).
9//! 
10//! ## Example 
11//! ```rust
12//! use std::time::Duration;
13//! use async_timeout::Timeout;
14//! use tokio::sync::Notify;
15//! 
16//! #[tokio::main]
17//! async fn main() {
18//!     let event = Arc::new(Notify::new());
19//!     let timer = Instant::now();
20//!     {
21//!         let event = event.clone();
22//!         // Let's notify our event after 3 seconds
23//!         Timeout::set(Duration::from_secs(3), async move {
24//!             event.notify_one();
25//!         }).await;
26//!     }
27//!     event.notified().await;
28//!     println!("{} seconds elapsed", timer.elapsed().as_secs());
29//! }
30//! ```
31//! [async_channel]: https://crates.io/crates/async-channel
32//! [Notify]: https://docs.rs/tokio/1.44.2/tokio/sync/struct.Notify.html
33mod timeout;
34
35pub use timeout::Timeout;