1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! `timedmap` provides a thread-safe hash map with expiring key-value pairs and
//! automatic cleanup mechnaisms for popular async runtimes.
//!
//! # Basic Example
//! ```
//! use timedmap::TimedMap;
//! use std::time::Duration;
//!
//! let tm = TimedMap::new();
//! tm.insert("foo", 1, Duration::from_millis(100));
//! tm.insert("bar", 2, Duration::from_millis(200));
//! tm.insert("baz", 3, Duration::from_millis(300));
//! assert_eq!(tm.get(&"foo"), Some(1));
//! assert_eq!(tm.get(&"bar"), Some(2));
//! assert_eq!(tm.get(&"baz"), Some(3));
//!
//! std::thread::sleep(Duration::from_millis(120));
//! assert_eq!(tm.get(&"foo"), None);
//! assert_eq!(tm.get(&"bar"), Some(2));
//! assert_eq!(tm.get(&"baz"), Some(3));
//!
//! std::thread::sleep(Duration::from_millis(100));
//! assert_eq!(tm.get(&"foo"), None);
//! assert_eq!(tm.get(&"bar"), None);
//! assert_eq!(tm.get(&"baz"), Some(3));
//! ```
//!
//! # Cleanup Example
//!
//! You can use the `start_cleaner` function to automatically clean up
//! expired key-value pairs in given time intervals using popular
//! async runtimes.
//!
//! > Currently, only implementations for `tokio` and `actix-rt`
//! are available. Implentations for other popular runtimes are
//! planned in the future. If you want to contribute an implementation,
//! feel free to create a
//! [pull request](https://github.com/zekroTJA/timedmap-rs). 😄
//!
//! ```
//! use timedmap::{TimedMap, start_cleaner};
//! use std::time::Duration;
//! use std::sync::Arc;
//!
//! let tm = Arc::new(TimedMap::new());
//! tm.insert("foo", 1, Duration::from_secs(60));
//!
//! # #[cfg(feature = "tokio")]
//! # tokio_test::block_on(async {
//! let cancel = start_cleaner(tm, Duration::from_secs(10));
//!
//! cancel();
//! # });
//! ```
pub use crate*;
pub use crate*;
pub use crate*;