Crates.io | tokio_delayed_queue |
lib.rs | tokio_delayed_queue |
version | 0.1.2 |
source | src |
created_at | 2024-05-25 09:04:03.756765 |
updated_at | 2024-05-27 08:21:38.34112 |
description | Asynchronous delayed queue for Tokio runtime. |
homepage | |
repository | https://github.com/DevNulPavel/tokio_delayed_queue |
max_upload_size | |
id | 1251855 |
size | 28,719 |
Asynchronous delayed queue for Tokio runtime.
let queue = DelayedQueue::new(16);
// Push
queue.push(1, Duration::from_secs(1)).await;
queue.push(1, Duration::from_secs(2)).await;
// Pop
let v = queue.pop().await;
assert_eq!(v, 1);
// Other future
let join = tokio::spawn({
let queue = queue.clone();
async move {
// Cancelled 1
let dropped_future = queue.pop();
drop(dropped_future);
// Cancelled 2
let dropped_future = queue.pop();
drop(dropped_future);
// Pop
let v = queue.pop().await;
assert_eq!(v, 1);
// Pop
let v = queue.pop().await;
assert_eq!(v, 1);
}
});
// Push
queue.push(1, Duration::from_secs(2)).await;
join.await.unwrap();