Page
Library
Module
Module type
Parameter
Class
Class type
Source
Kcas_data.Queue
SourceFirst-In First-Out (FIFO) queue.
The interface provides a subset of the OCaml Stdlib.Queue
module. transfer
and add_seq
are not provided at all. Compositional versions of iter
, fold
, peek
, top
, and take
are not provided.
The queue implementation is designed to avoid contention between a producer and a consumer operating concurrently. The implementation is also designed to avoid starvation. Performance in most concurrent use cases should be superior to what can be achieved with one or two locks.
The type of queues containing elements of type 'a
.
to_seq s
returns a domain safe sequence for iterating through the elements of the queue front to back.
The sequence is based on a constant time, O(1)
, snapshot of the queue and modifications of the queue have no effect on the sequence.
peek_opt q
returns the first element in queue q
, without removing it from the queue, or returns None
if the queue is empty.
peek_blocking q
returns the first element in queue q
, without removing it from the queue, or blocks waiting for the queue to become non-empty.
take_blocking q
removes and returns the first element in queue q
, or blocks waiting for the queue to become non-empty.
take_opt q
removes and returns the first element in queue q
, or returns None
if the queue is empty.
take_all q
removes and returns a domain safe sequence for iterating through all the elements that were in the queue front to back.
peek q
returns the first element in queue s
, or raises Empty
if the queue is empty.
take s
removes and returns the first element in queue q
, or raises Empty
if the queue is empty.