# Async Timeouts Helper
It is a simple instrument to delay execution of an async task with additional methods:
* [reset] timeout with a new value, i.e. to delay execution of your task;
* [restart] timeout with a new or previous task;
* [stop] the timer before your task will be executed;
* [finished] — check if the timer of the task is over or not.
It is convinient to use this crate with [Notify] or different
channels (i.e. [async_channel]).
## Example
```rust
use std::time::{Duration, Instant};
use async_timeouts::Timeout;
use tokio::sync::Notify;
use std::sync::Arc;
#[tokio::main]
async fn main() {
let event = Arc::new(Notify::new());
let timer = Instant::now();
{
let event = event.clone();
// Let's notify our event after 3 seconds
Timeout::set(Duration::from_secs(3), async move {
event.notify_one();
}).await;
}
event.notified().await;
println!("{} seconds elapsed", timer.elapsed().as_secs());
}
```
[async_channel]: https://crates.io/crates/async-channel
[Notify]: https://docs.rs/tokio/1.44.2/tokio/sync/struct.Notify.html
[reset]: https://docs.rs/async-timeouts/latest/async_timeouts/struct.Timeout.html#method.reset
[restart]: https://docs.rs/async-timeouts/latest/async_timeouts/struct.Timeout.html#method.restart
[stop]: https://docs.rs/async-timeouts/latest/async_timeouts/struct.Timeout.html#method.stop
[finished]: https://docs.rs/async-timeouts/latest/async_timeouts/struct.Timeout.html#method.finished
Take a look at more complex examples:
* [example with channels],
* [restart timeout].
[example with channels]: https://altlinux.space/writers/async-timeouts/src/branch/main/examples/usage_with_channels.rs
[restart timeout]: https://altlinux.space/writers/async-timeouts/src/branch/main/examples/restart_timeout.rs