Hyperlinkv0.8.0-beta.28

TxSemaphore

TxSemaphore.availableconsteffect/TxSemaphore.ts:170
(self: TxSemaphore): Effect.Effect<number>

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
})
combinatorscapacity
export const available = (self: TxSemaphore): Effect.Effect<number> => TxRef.get(self.permitsRef)