Crates.io | delay_map |
lib.rs | delay_map |
version | 0.4.0 |
source | src |
created_at | 2022-01-31 01:52:40.637119 |
updated_at | 2024-07-11 05:53:36.782316 |
description | HashMap collections whose entries expire after a given time |
homepage | |
repository | https://github.com/agemanning/delay_map |
max_upload_size | |
id | 524300 |
size | 34,410 |
This crate contains two data structures, [HashSetDelay
] and [HashMapDelay
]. These
behave like the standard library HashSet and HashMaps with the added feature that entries
inserted into the mappings expire after a fixed period of time.
use delay_map::HashMapDelay;
use futures::prelude::*;
// Set a default timeout for entries
let mut delay_map = HashMapDelay::new(std::time::Duration::from_secs(1));
tokio_test::block_on(async {
delay_map.insert(1, "entry_1");
delay_map.insert(2, "entry_2");
if let Some(Ok((key, value))) = delay_map.next().await {
println!("Entry 1: {}, {}", key, value);
}
if let Some(Ok((key, value))) = delay_map.next().await {
println!("Entry 2: {}, {}", key,value);
}
});