Hyperlinkv0.8.0-beta.28

TxQueue

TxQueue.slidingconsteffect/TxQueue.ts:503
<A = never, E = never>(capacity: number): Effect.Effect<TxQueue<A, E>>

Creates a new sliding TxQueue with the specified capacity that evicts old items when full.

Details

This function returns a new TxQueue reference with sliding strategy. No existing TxQueue instances are modified.

Example (Creating sliding queues)

import { Effect, TxQueue } from "effect"

const program = Effect.gen(function*() {
  // Create a sliding queue with capacity 2
  const queue = yield* TxQueue.sliding<number>(2)

  // Fill to capacity
  yield* TxQueue.offer(queue, 1)
  yield* TxQueue.offer(queue, 2)

  // This will evict item 1 and add 3
  yield* TxQueue.offer(queue, 3)

  const item = yield* TxQueue.take(queue)
  console.log(item) // 2 (item 1 was evicted)
})
constructors
Source effect/TxQueue.ts:50314 lines
export const sliding = <A = never, E = never>(
  capacity: number
): Effect.Effect<TxQueue<A, E>> =>
  Effect.gen(function*() {
    const items = yield* TxChunk.empty<A>()
    const stateRef = yield* TxRef.make<State<A, E>>({ _tag: "Open" })

    const txQueue = Object.create(TxQueueProto)
    txQueue.strategy = "sliding"
    txQueue.capacity = capacity
    txQueue.items = items
    txQueue.stateRef = stateRef
    return txQueue
  }).pipe(Effect.tx)