effect-io-ai

Package: effect
Module: TxSemaphore

TxSemaphore.available

Gets the current number of available permits in the semaphore.

When to use

Use to inspect how many permits are currently available.

Example (Checking available permits)

import { Console, Effect, TxSemaphore } from "effect"

const program = Effect.gen(function*() {
  const semaphore = yield* TxSemaphore.make(5)

  // Check available permits before acquiring
  const before = yield* TxSemaphore.available(semaphore)
  yield* Console.log(`Available permits: ${before}`) // 5

  // Acquire some permits
  yield* TxSemaphore.acquire(semaphore)
  yield* TxSemaphore.acquire(semaphore)

  // Check available permits after acquiring
  const after = yield* TxSemaphore.available(semaphore)
  yield* Console.log(`Available permits: ${after}`) // 3
})

See

Signature

declare const available: (self: TxSemaphore) => Effect.Effect<number>

Source

Since v2.0.0