Crates.io | fibers_timeout_queue |
lib.rs | fibers_timeout_queue |
version | 0.1.0 |
source | src |
created_at | 2018-09-13 16:51:29.799799 |
updated_at | 2018-09-13 16:51:29.799799 |
description | Timeout queue based on `fibers` crate |
homepage | https://github.com/sile/fibers_timeout_queue |
repository | https://github.com/sile/fibers_timeout_queue |
max_upload_size | |
id | 84559 |
size | 12,114 |
This crate provides a timeout queue based on fibers
crate.
use fibers_timeout_queue::TimeoutQueue;
use std::time::Duration;
use std::thread;
let mut queue = TimeoutQueue::new();
assert_eq!(queue.pop(), None); // `queue` is empty
queue.push(1, Duration::from_millis(1000));
queue.push(2, Duration::from_millis(100));
queue.push(3, Duration::from_millis(10));
assert_eq!(queue.pop(), None); // No expired items
thread::sleep(Duration::from_millis(50));
assert_eq!(queue.pop(), Some(3)); // There is an expired item
assert_eq!(queue.pop(), None);