Crates.io | snooze |
lib.rs | snooze |
version | 0.1.0 |
source | src |
created_at | 2020-10-30 16:47:05.256596 |
updated_at | 2020-10-30 16:47:05.256596 |
description | An timeout based event notifier for Rust |
homepage | |
repository | https://github.com/MarinPostma/snooze |
max_upload_size | |
id | 307026 |
size | 6,738 |
Snooze is a crate that allows you to trigger the sending of a message with a specific delay or interval. This is usefull to handle TTL for example.
Basically, you just need to instanciate an instance of a Notifier
, to which you register events to trigger
at a certain time:
let mut notifier = Nofifier::new();
// do not drop the handle
notifier.notify_afer(Duration::from_secs(1), "world");
let _handle = notifier.notify_interval(Duration::from_secs(2), "hello");
assert_eq!(notifier.next().await, Some("hello"));
assert_eq!(notifier.next().await, Some("world"));
assert_eq!(notifier.next().await, Some("hello"));