BlockingMpscQueue

zio.blocks.streams.queues.BlockingMpscQueue
final class BlockingMpscQueue[A <: AnyRef](capacity: Int)

A blocking MPSC (multi-producer, single-consumer) queue.

Backed by MpscRingBuffer for the fast path; uses LockSupport.park and LockSupport.unpark for blocking when the buffer is full or empty.

Multiple threads may call offer concurrently. Only a single thread may call take, drain, isEmpty, or isClosed.

Multi-producer parking: a single producerWaiter volatile slot is used. One producer registers and gets fast-path unpark from consumer. Others use parkNanos(1000) (1µs) to retry — VT-friendly, no starvation.

Null elements are not permitted.

Value parameters

capacity

The logical capacity. Rounded up to the next power of two internally.

Attributes

Source
BlockingMpscQueue.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def close(): Unit

Closes the queue, unblocking any waiting thread on either side.

Closes the queue, unblocking any waiting thread on either side.

Attributes

Source
BlockingMpscQueue.scala
def drain(consumer: A => Unit, limit: Int): Int

Drains up to limit elements from the queue and passes each to consumer.

Drains up to limit elements from the queue and passes each to consumer.

Value parameters

consumer

callback invoked for each drained element

limit

maximum number of elements to drain

Attributes

Returns

number of elements drained

Source
BlockingMpscQueue.scala
def isClosed: Boolean

Whether the queue has been closed.

Whether the queue has been closed.

Attributes

Source
BlockingMpscQueue.scala
def isEmpty: Boolean

Whether the ring buffer contains no elements.

Whether the ring buffer contains no elements.

Attributes

Source
BlockingMpscQueue.scala
def offer(a: A): Boolean

Offers an element to the queue, blocking until space is available or the queue is closed. Returns true on success, false if the queue was closed.

Offers an element to the queue, blocking until space is available or the queue is closed. Returns true on success, false if the queue was closed.

Attributes

Source
BlockingMpscQueue.scala
def take(): A

Takes an element from the queue, blocking until one is available or the queue is closed. Returns the element, or null if closed and empty.

Takes an element from the queue, blocking until one is available or the queue is closed. Returns the element, or null if closed and empty.

Attributes

Source
BlockingMpscQueue.scala