Hyperlinkv0.8.0-beta.28

Queue

Queue.droppingconsteffect/Queue.ts:562
<A, E = never>(capacity: number): Effect<Queue<A, E>>

Creates a bounded queue with dropping strategy. When the queue reaches capacity, new elements are dropped and the offer operation returns false.

When to use

Use when you need producer offers not to block while preserving existing queued messages, even if new messages may be dropped when the queue is full.

Example (Creating dropping queues)

import { Effect, Queue } from "effect"

const program = Effect.gen(function*() {
  const queue = yield* Queue.dropping<number>(2)

  // Fill the queue to capacity
  const success1 = yield* Queue.offer(queue, 1)
  const success2 = yield* Queue.offer(queue, 2)
  console.log(success1, success2) // true, true

  // This will be dropped
  const success3 = yield* Queue.offer(queue, 3)
  console.log(success3) // false

  const all = yield* Queue.takeAll(queue)
  console.log(all) // [1, 2] - element 3 was dropped
})
constructors
Source effect/Queue.ts:5622 lines
export const dropping = <A, E = never>(capacity: number): Effect<Queue<A, E>> =>
  make({ capacity, strategy: "dropping" })