(self: TxSemaphore): Effect.Effect<number>Gets the current number of available permits in the semaphore.
When to use
Use to inspect how many permits are currently available.
Example (Checking available permits)
import { Console, Effect, TxSemaphore } from "effect"
const program = Effect.gen(function*() {
const semaphore = yield* TxSemaphore.make(5)
// Check available permits before acquiring
const before = yield* TxSemaphore.available(semaphore)
yield* Console.log(`Available permits: ${before}`) // 5
// Acquire some permits
yield* TxSemaphore.acquire(semaphore)
yield* TxSemaphore.acquire(semaphore)
// Check available permits after acquiring
const after = yield* TxSemaphore.available(semaphore)
yield* Console.log(`Available permits: ${after}`) // 3
})export const const available: (
self: TxSemaphore
) => Effect.Effect<number>
Gets the current number of available permits in the semaphore.
When to use
Use to inspect how many permits are currently available.
Example (Checking available permits)
import { Console, Effect, TxSemaphore } from "effect"
const program = Effect.gen(function*() {
const semaphore = yield* TxSemaphore.make(5)
// Check available permits before acquiring
const before = yield* TxSemaphore.available(semaphore)
yield* Console.log(`Available permits: ${before}`) // 5
// Acquire some permits
yield* TxSemaphore.acquire(semaphore)
yield* TxSemaphore.acquire(semaphore)
// Check available permits after acquiring
const after = yield* TxSemaphore.available(semaphore)
yield* Console.log(`Available permits: ${after}`) // 3
})
available = (self: TxSemaphore(parameter) self: {
permitsRef: TxRef.TxRef<number>;
capacity: number;
toString: () => string;
toJSON: () => unknown;
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; <…;
}
self: TxSemaphore): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<number> => import TxRefTxRef.const get: <A>(
self: TxRef<A>
) => Effect.Effect<A>
Reads the current value of the TxRef.
When to use
Use to read the current value of a TxRef.
Example (Reading transactional references)
import { Effect, TxRef } from "effect"
const program = Effect.gen(function*() {
const counter = yield* TxRef.make(42)
// Read the value within a transaction
const value = yield* Effect.tx(
TxRef.get(counter)
)
console.log(value) // 42
})
get(self: TxSemaphore(parameter) self: {
permitsRef: TxRef.TxRef<number>;
capacity: number;
toString: () => string;
toJSON: () => unknown;
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; <…;
}
self.TxSemaphore.permitsRef: TxRef.TxRef<number>(property) TxSemaphore.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)