Module queue

Source
Expand description

Transmit any number of values of the same type, then (after transmitting all) proceed according to a continuation session. The two sides, receiving and sending, are Dequeue and Enqueue, respectively.

The order of values popped out of Dequeue is the same as their push order into Enqueue – first-in, first-out.

Pushing values into Enqueue is always non-blocking – any number of values may be pushed without waiting for Dequeue to receive them.

These queue sessions are just a standardization of a common recursive pattern. They are fully equivalent to:

enum Queue<T, S: Session> {
    Item(T, Dequeue<T, S>),
    Closed(S),
}

// naked definitions of the two sides of the queue
type Dequeue<T, S> = Recv<Queue<T, S>>;
type Enqueue<T, S> = Send<Queue<T, Dual<S>>>;

Structs§

Dequeue
Produces an arbitrary number of values of type T, then proceeds according to S. Its dual is Enqueue<T, Dual<S>>.
DequeueStream
A Stream of Next<T, S> producing all items from the queue before producing its final continuation.
DequeueStream1
A Stream producing all items from a Dequeue.
Enqueue
Accepts an arbitrary number of values of type T, then proceeds according to S. Its dual is Dequeue<T, Dual<S>>.

Enums§

Next
The Stream::Item of DequeueStream<S, T>, distinguishing between a popped item and a closed queue with its final continuation.
Queue
The result of Dequeue::pop.