tokio_delayed_queue

Crates.iotokio_delayed_queue
lib.rstokio_delayed_queue
version0.2.0
sourcesrc
created_at2024-05-25 09:04:03.756765
updated_at2024-10-31 05:44:36.24167
descriptionAsynchronous delayed queue for Tokio runtime.
homepage
repositoryhttps://github.com/DevNulPavel/tokio_delayed_queue
max_upload_size
id1251855
size32,024
(DevNulPavel)

documentation

https://docs.rs/tokio_delayed_queue

README

Tokio delayed queue

Asynchronous delayed queue for Tokio runtime.

Features

  • multi-consume
  • multi-produce
  • fixed queue size
  • atomic pop with pop-future cancelation

Example

let queue = DelayedQueue::new_bound(NonZeroUsize::new(16).unwrap());

// 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();
Commit count: 11

cargo fmt