Crate futures_delay_queue[][src]

Expand description

A queue of delayed elements backed by futures-timer that can be used with both:

An element is inserted into the DelayQueue and will be yielded once the specified deadline has been reached.

The delayed items can be consumed through a channel returned at creation.


The delays are spawned and a timeout races against a reset channel that can be triggered with the DelayHandle. If the timeout occurs before cancelation or a reset the item is yielded through the receiver channel.


A DelayQueue and a channel for receiving the expired items is created using the delay_queue function.

Elements are inserted into DelayQueue using the insert or insert_at methods. A deadline is provided with the item and a DelayHandle is returned. The delay handle is used to remove the entry.

The delays can be configured with the reset_at or the reset method or canceled by calling the cancel method. Dropping the handle will not cancel the delay.

Modification of the delay fails if the delayed item expired in the meantime. In this case an ErrorAlreadyExpired will be returned. If modification succeeds the handle will be returned back to the caller.


use futures_delay_queue::delay_queue;
use std::time::Duration;

async fn main() {
    let (delay_queue, rx) = delay_queue::<i32>();

    let delay_handle = delay_queue.insert(1, Duration::from_millis(20));

    let delay_handle = delay_queue.insert(2, Duration::from_millis(10));

    let delay_handle = delay_queue.insert(3, Duration::from_millis(30));

    assert_eq!(rx.receive().await, Some(3));
    assert_eq!(rx.receive().await, Some(1));

    assert_eq!(rx.receive().await, None);



A handle to cancel the corresponding delay of an item in DelayQueue.


A queue for managing delayed items.


The error type for delays that are modified after they have already expired in the DelayQueue.


The sending side of a channel which can be used to exchange values between concurrent tasks.



Creates a dynamically growing delay queue and a multi consumer channel for receiving expired items.

Type Definitions


A GenericReceiver implementation backed by parking_lot.