Package: effect
Module: TxSemaphore
Acquires a single permit from the semaphore. If no permits are available, the effect will block until one becomes available.
When to use
Use to manually acquire one permit transactionally, waiting until one is available.
Example (Acquiring a permit)
import { Console, Effect, TxSemaphore } from "effect"
const program = Effect.gen(function*() {
const semaphore = yield* TxSemaphore.make(2)
yield* Console.log("Acquiring first permit...")
yield* TxSemaphore.acquire(semaphore)
yield* Console.log("First permit acquired")
yield* Console.log("Acquiring second permit...")
yield* TxSemaphore.acquire(semaphore)
yield* Console.log("Second permit acquired")
const available = yield* TxSemaphore.available(semaphore)
yield* Console.log(`Available permits: ${available}`) // 0
})
See
tryAcquire for a non-blocking single-permit attemptrelease for returning one permitwithPermit for automatic acquire and release around an effectSignature
declare const acquire: (self: TxSemaphore) => Effect.Effect<void>
Since v2.0.0