(permits: number): SemaphoreCreates a Semaphore synchronously with the specified total
number of permits.
When to use
Use to construct a semaphore synchronously when an immediate value is required outside an Effect workflow.
Example (Creating an unsafe semaphore)
import { Effect, Semaphore } from "effect"
const semaphore = Semaphore.makeUnsafe(3)
const task = (id: number) =>
semaphore.withPermits(1)(
Effect.gen(function*() {
yield* Effect.log(`Task ${id} started`)
yield* Effect.sleep("1 second")
yield* Effect.log(`Task ${id} completed`)
})
)
// Only 3 tasks can run concurrently
const program = Effect.all([
task(1),
task(2),
task(3),
task(4),
task(5)
], { concurrency: "unbounded" })constructors
Source effect/Semaphore.ts:1901 lines
export const const makeUnsafe: (
permits: number
) => Semaphore
Creates a Semaphore synchronously with the specified total
number of permits.
When to use
Use to construct a semaphore synchronously when an immediate value is
required outside an Effect workflow.
Example (Creating an unsafe semaphore)
import { Effect, Semaphore } from "effect"
const semaphore = Semaphore.makeUnsafe(3)
const task = (id: number) =>
semaphore.withPermits(1)(
Effect.gen(function*() {
yield* Effect.log(`Task ${id} started`)
yield* Effect.sleep("1 second")
yield* Effect.log(`Task ${id} completed`)
})
)
// Only 3 tasks can run concurrently
const program = Effect.all([
task(1),
task(2),
task(3),
task(4),
task(5)
], { concurrency: "unbounded" })
makeUnsafe = (permits: numberpermits: number): Semaphore => new constructor SemaphoreImpl(permits: number): SemaphoreImplSemaphoreImpl(permits: numberpermits)Referenced by 5 symbols