Hyperlinkv0.8.0-beta.28

TxQueue

TxQueue.shutdownconsteffect/TxQueue.ts:1345
<A, E>(self: TxEnqueue<A, E>): Effect.Effect<boolean>

Shuts down the queue immediately by clearing all items and interrupting it (legacy compatibility).

Details

This operation clears all items from the queue using clear, then interrupts the queue using interrupt. This function mutates the original TxQueue by clearing its contents and marking it as shutdown. It does not return a new TxQueue reference.

Example (Shutting down 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

  yield* TxQueue.shutdown(queue)

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

  const isShutdown = yield* TxQueue.isShutdown(queue)
  console.log(isShutdown) // true (interrupted)
})
combinators
export const shutdown = <A, E>(self: TxEnqueue<A, E>): Effect.Effect<boolean> =>
  Effect.gen(function*() {
    yield* Effect.ignore(clear(self))
    return yield* interrupt(self)
  }).pipe(Effect.tx)
Referenced by 2 symbols