effect-io-ai

Package: effect
Module: TxSemaphore

TxSemaphore.make

Creates a new TxSemaphore with the specified number of permits.

When to use

Use to create a transactional semaphore with a fixed permit capacity.

Example (Creating a semaphore)

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

// Create a semaphore for managing concurrent access to a resource pool
const program = Effect.gen(function*() {
  // Create a semaphore with 3 permits for a connection pool
  const connectionSemaphore = yield* TxSemaphore.make(3)

  // Check initial state
  const available = yield* TxSemaphore.available(connectionSemaphore)
  const capacity = yield* TxSemaphore.capacity(connectionSemaphore)

  yield* Console.log(
    `Created semaphore with ${capacity} permits, ${available} available`
  )
  // Output: "Created semaphore with 3 permits, 3 available"
})

See

Signature

declare const make: (permits: number) => Effect.Effect<TxSemaphore>

Source

Since v2.0.0