BlockingSpscQueue

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

A blocking single-producer single-consumer queue.

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

Two separate waiter slots are maintained — consumerWaiter and producerWaiter — so that each side registers in its own slot without overwriting the other side's registration. A single shared slot would introduce a lost-wakeup race: the producer could overwrite the consumer's registration before the consumer parks, causing the consumer's park to return via stale permit and then clear the producer's registration, leaving the producer permanently blocked.

Null elements are not permitted.

Value parameters

capacity

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

Attributes

Source
BlockingSpscQueue.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
BlockingSpscQueue.scala
def isClosed: Boolean

Whether the queue has been closed.

Whether the queue has been closed.

Attributes

Source
BlockingSpscQueue.scala
def isEmpty: Boolean

Whether the ring buffer contains no elements.

Whether the ring buffer contains no elements.

Attributes

Source
BlockingSpscQueue.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
BlockingSpscQueue.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
BlockingSpscQueue.scala