Module CCBlockingQueue
Blocking Queue
This queue has a limited size. Pushing a value on the queue when it is full will block.
- since
- 0.16
val create : int -> 'a t
Create a new queue of size
n
. Usingn=max_int
amounts to using an infinite queue (2^61 items is a lot to fit in memory); usingn=1
amounts to using a box with 0 or 1 elements inside.- raises Invalid_argument
if
n < 1
.
val push : 'a t -> 'a -> unit
push q x
pushesx
intoq
, blocking if the queue is full.
val take : 'a t -> 'a
Take the first element, blocking if needed.
val push_list : 'a t -> 'a list -> unit
Push items of the list, one by one.
val take_list : 'a t -> int -> 'a list
take_list n q
takesn
elements out ofq
.
val try_take : 'a t -> 'a option
Take the first element if the queue is not empty, return
None
otherwise.
val try_push : 'a t -> 'a -> bool
try_push q x
pushesx
intoq
ifq
is not full, in which case it returnstrue
. If it fails becauseq
is full, it returnsfalse
.
val peek : 'a t -> 'a option
peek q
returnsSome x
ifx
is the first element ofq
, otherwise it returnsNone
.
val size : _ t -> int
Number of elements currently in the queue.
val capacity : _ t -> int
Number of values the queue can hold.