(permits: number): Effect.Effect<TxSemaphore>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"
})Source effect/TxSemaphore.ts:1269 lines
export const const make: (
permits: number
) => Effect.Effect<TxSemaphore>
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"
})
make = (permits: numberpermits: number): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<TxSemaphore> =>
import EffectEffect.gen(function*() {
if (permits: numberpermits < 0) {
return yield* import EffectEffect.die(new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error("Permits must be non-negative"))
}
const const permitsRef: TxRef.TxRef<number>const permitsRef: {
version: number;
pending: Map<unknown, () => void>;
value: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
permitsRef = yield* import TxRefTxRef.make(permits: numberpermits)
return const makeTxSemaphore: (
permitsRef: TxRef.TxRef<number>,
capacity: number
) => TxSemaphore
makeTxSemaphore(const permitsRef: TxRef.TxRef<number>const permitsRef: {
version: number;
pending: Map<unknown, () => void>;
value: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
permitsRef, permits: numberpermits)
}).pipe(import EffectEffect.tx)