4 releases

new 0.2.0 Oct 31, 2024
0.1.2 May 27, 2024
0.1.1 May 25, 2024
0.1.0 May 25, 2024

#453 in Asynchronous

Download history 4/week @ 2024-07-28 6/week @ 2024-09-22 2/week @ 2024-09-29 132/week @ 2024-10-27

132 downloads per month

MIT and GPL-3.0-or-later

29KB
254 lines

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();

Dependencies

~2.7–8.5MB
~66K SLoC