Queue is a lightweight, asynchronous queue for Effect programs. Queues support both bounded and unbounded operation, with different backpressure strategies.
Types
Queue
Queue<A> can both enqueue and dequeue values of type A.
Enqueue
Dequeue
Creating Queues
bounded
Creates a bounded queue with backpressure. When the queue is full,offer will suspend until space is available.
unbounded
Creates an unbounded queue that never reaches capacity.dropping
Creates a bounded queue with dropping strategy. When full, new elements are dropped and old elements remain.sliding
Creates a bounded queue with sliding strategy. When full, new elements are added and old elements are dropped.Offering Values
offer
Places a value in the queue.offerAll
Places multiple values in the queue.unsafeOffer
Unsafely offers a value without the fiber runtime.Taking Values
take
Takes the oldest value from the queue. Suspends if the queue is empty.takeAll
Takes all values from the queue. Returns an empty chunk if the queue is empty.takeUpTo
Takes up to a maximum number of values from the queue.takeBetween
Takes between min and max values from the queue. Suspends until at least min values are available.poll
Returns the first value asSome<A>, or None if the queue is empty.
Queue Information
size
Gets the current size of the queue.capacity
Gets the capacity of the queue.isEmpty
Checks if the queue is empty.isFull
Checks if the queue is full.Shutdown
shutdown
Interrupts any fibers suspended onoffer or take.