effect-io-ai

Package: effect
Module: TxQueue

TxQueue.clear

Removes and returns all currently buffered elements without changing the queue state.

Details

If the queue is already done with a Cause.Done error, returns an empty array. If the queue is done for any other cause, including interruption or failure, that cause is propagated.

Example (Clearing queues)

import { Effect, TxQueue } from "effect"

const program = Effect.gen(function*() {
  const queue = yield* TxQueue.bounded<number>(10)
  yield* TxQueue.offerAll(queue, [1, 2, 3, 4, 5])

  const sizeBefore = yield* TxQueue.size(queue)
  console.log(sizeBefore) // 5

  const cleared = yield* TxQueue.clear(queue)
  console.log(cleared) // [1, 2, 3, 4, 5]

  const sizeAfter = yield* TxQueue.size(queue)
  console.log(sizeAfter) // 0
})

Signature

declare const clear: <A, E>(self: TxEnqueue<A, E>) => Effect.Effect<Array<A>, ExcludeDone<E>>

Source

Since v4.0.0