<K>(self: PartitionedSemaphore<K>, key: K, permits: number): <A, E, R>(
effect: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
<K, A, E, R>(
self: PartitionedSemaphore<K>,
key: K,
permits: number,
effect: Effect.Effect<A, E, R>
): Effect.Effect<A, E, R>Runs an effect after acquiring permits for a partition, then releases those permits when the effect exits.
When to use
Use to guard weighted partitioned work with automatic permit acquisition and release around an effect.
Details
Permit acquisition may wait according to take semantics. Once acquired,
the permits are released even if the wrapped effect fails or is interrupted.
Gotchas
Requests for more permits than the semaphore capacity never complete. Requests for zero or a negative number of permits run the effect without acquiring anything.
export const const withPermits: {
<K>(
self: PartitionedSemaphore<K>,
key: K,
permits: number
): <A, E, R>(
effect: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
<K, A, E, R>(
self: PartitionedSemaphore<K>,
key: K,
permits: number,
effect: Effect.Effect<A, E, R>
): Effect.Effect<A, E, R>
}
Runs an effect after acquiring permits for a partition, then releases those
permits when the effect exits.
When to use
Use to guard weighted partitioned work with automatic permit acquisition and
release around an effect.
Details
Permit acquisition may wait according to take semantics. Once acquired,
the permits are released even if the wrapped effect fails or is interrupted.
Gotchas
Requests for more permits than the semaphore capacity never complete.
Requests for zero or a negative number of permits run the effect without
acquiring anything.
withPermits: {
<function (type parameter) K in <K>(self: PartitionedSemaphore<K>, key: K, permits: number): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>K>(
self: PartitionedSemaphore<K>(parameter) self: {
capacity: number;
available: Effect.Effect<number>;
take: (key: K, permits: number) => Effect.Effect<void>;
release: (permits: number) => Effect.Effect<number>;
withPermits: (key: K, permits: number) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
withPermit: (key: K) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
withPermitsIfAvailable: (permits: number) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<Option.Option<A>, E, R>;
}
self: interface PartitionedSemaphore<in K>A PartitionedSemaphore controls access to a shared permit pool while
tracking waiters by partition key.
When to use
Use to coordinate shared permits across partition keys so waiting groups make
progress without one group monopolizing the pool.
Details
Waiting permits are distributed across partitions in round-robin order.
PartitionedSemaphore<function (type parameter) K in <K>(self: PartitionedSemaphore<K>, key: K, permits: number): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>K>,
key: Kkey: function (type parameter) K in <K>(self: PartitionedSemaphore<K>, key: K, permits: number): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>K,
permits: numberpermits: number
): <function (type parameter) A in <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>(effect: Effect.Effect<A, E, R>(parameter) effect: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effect: import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>
<function (type parameter) K in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>K, function (type parameter) A in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>(
self: PartitionedSemaphore<K>(parameter) self: {
capacity: number;
available: Effect.Effect<number>;
take: (key: K, permits: number) => Effect.Effect<void>;
release: (permits: number) => Effect.Effect<number>;
withPermits: (key: K, permits: number) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
withPermit: (key: K) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
withPermitsIfAvailable: (permits: number) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<Option.Option<A>, E, R>;
}
self: interface PartitionedSemaphore<in K>A PartitionedSemaphore controls access to a shared permit pool while
tracking waiters by partition key.
When to use
Use to coordinate shared permits across partition keys so waiting groups make
progress without one group monopolizing the pool.
Details
Waiting permits are distributed across partitions in round-robin order.
PartitionedSemaphore<function (type parameter) K in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>K>,
key: Kkey: function (type parameter) K in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>K,
permits: numberpermits: number,
effect: Effect.Effect<A, E, R>(parameter) effect: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effect: import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>
): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <K, A, E, R>(self: PartitionedSemaphore<K>, key: K, permits: number, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>
} = ((...args: any[]args: interface Array<T>Array<any>) => {
if (args: any[]args.Array<any>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length === 3) {
const [const self: anyself, const key: anykey, const permits: anypermits] = args: any[]args
return (effect: Effect.Effect<any, any, any>(parameter) effect: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effect: import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<any, any, any>) => const self: anyself.withPermits(const key: anykey, const permits: anypermits)(effect: Effect.Effect<any, any, any>(parameter) effect: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effect)
}
const [const self: anyself, const key: anykey, const permits: anypermits, const effect: anyeffect] = args: any[]args
return const self: anyself.withPermits(const key: anykey, const permits: anypermits)(const effect: anyeffect)
}) as any