QueueType
Queue
Queue<'a> hands values from producer fibers to one logical consumer, in FIFO order, with an overflow strategy chosen
when it is created. This module creates queues and offers to them; take values, inspect, and shut a queue down with the
Dequeue functions, which accept a Queue.
Create a queue with make and a QueueStrategy, or with a shorthand:
bounded suspends producers while full, dropping discards the new
value, sliding evicts the oldest, and unbounded never refuses.
makeScoped shuts the queue down when the current scope closes.
Interrupting a suspended offer never enqueues its value, and interrupting a suspended take never
loses one. When zero or many consumers must each see every value, use a Hub instead.
tryOffer returns immediately and can be called from a synchronous callback. Its
QueueTryOfferResult distinguishes acceptance, a full back-pressure queue, discard, eviction, and shutdown. A Full
or Shutdown result leaves the offered value outside the queue.
Read the Queue guide for strategies, batching, shutdown, and draining on stop.
Specification
Summary
| Name | Signature | Synopsis |
|---|---|---|
| Operations | ||
| make | Queue.make strategy | Creates a queue with the given overflow strategy. |
| makeScoped | Queue.makeScoped strategy | Creates a queue that is shut down when the current scope closes. |
| bounded | Queue.bounded capacity | Creates a lossless queue whose offer suspends while it holds capacity values. |
| dropping | Queue.dropping capacity | Creates a queue whose offer discards the new value and returns false when full. |
| sliding | Queue.sliding capacity | Creates a queue whose offer evicts the oldest value when full and returns true. |
| unbounded | Queue.unbounded () | Creates a queue that never rejects or suspends an offer. |
| offer | Queue.offer value queue | Adds a value according to the queue's strategy. |
| tryOffer | Queue.tryOffer value queue | Tries to add a value immediately, without starting a Flow or suspending the caller. |
| offerAll | Queue.offerAll values queue | Adds values in order according to the queue's strategy. |
Operations
Parameters
| Name | Type | Description |
|---|---|---|
| strategy | QueueStrategy |
Returns
Verification Examples
flow {
let! (jobs: Queue<string>) = Queue.makeScoped (QueueStrategy.BackPressure 64)
do! jobs |> Queue.offer "first job" |> Flow.ignore
}
|> Flow.scopedParameters
| Name | Type | Description |
|---|---|---|
| values | 'a seq | |
| queue | Queue<'a> |
Returns
Verification Examples
flow {
let! (samples: Queue<float>) = Queue.unbounded ()
do! samples |> Queue.offerAll [ 1.0; 2.0; 3.0 ] |> Flow.ignore
return! samples |> Dequeue.takeUpTo 500
}
