Package: effect
Module: TxSemaphore
Tries to acquire a single permit from the semaphore without blocking,
returning true if successful or false if no permits are available.
When to use
Use to attempt a single-permit acquisition without retrying when no permit is available.
Example (Trying to acquire a permit)
import { Console, Effect, TxSemaphore } from "effect"
const program = Effect.gen(function*() {
const semaphore = yield* TxSemaphore.make(1)
// First try should succeed
const first = yield* TxSemaphore.tryAcquire(semaphore)
yield* Console.log(`First try: ${first}`) // true
// Second try should fail (no permits left)
const second = yield* TxSemaphore.tryAcquire(semaphore)
yield* Console.log(`Second try: ${second}`) // false
})
See
acquire for waiting until one permit is availabletryAcquireN for attempting to acquire multiple permits without blockingSignature
declare const tryAcquire: (self: TxSemaphore) => Effect.Effect<boolean>
Since v4.0.0