Hyperlinkv0.8.0-beta.28

TxSemaphore

TxSemaphore.capacityconsteffect/TxSemaphore.ts:202
(self: TxSemaphore): Effect.Effect<number>

Gets the maximum capacity (total permits) of the semaphore.

When to use

Use to inspect the fixed total number of permits managed by the semaphore.

Example (Checking semaphore capacity)

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

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

  const capacity = yield* TxSemaphore.capacity(semaphore)
  yield* Console.log(`Semaphore capacity: ${capacity}`) // 10

  // Capacity remains constant regardless of current permits
  yield* TxSemaphore.acquire(semaphore)
  const stillSame = yield* TxSemaphore.capacity(semaphore)
  yield* Console.log(`Capacity after acquire: ${stillSame}`) // 10
})
combinatorsavailable
export const capacity = (self: TxSemaphore): Effect.Effect<number> => Effect.succeed(self.capacity)