Hyperlinkv0.8.0-beta.28

PartitionedSemaphore

PartitionedSemaphore.takeconsteffect/PartitionedSemaphore.ts:401
<K>(key: K, permits: number): (
  self: PartitionedSemaphore<K>
) => Effect.Effect<void>
<K>(
  self: PartitionedSemaphore<K>,
  key: K,
  permits: number
): Effect.Effect<void>

Returns an effect that acquires the requested number of permits for the given partition key.

When to use

Use when you need manual permit acquisition for a partition and want to control acquisition and release as separate effects.

Details

If enough permits are available, the effect completes immediately. Otherwise it waits until released permits are assigned to this partition.

Gotchas

Requests for more permits than the semaphore capacity never complete. Requests for zero or a negative number of permits complete without acquiring anything.

export const take: {
  <K>(key: K, permits: number): (self: PartitionedSemaphore<K>) => Effect.Effect<void>
  <K>(self: PartitionedSemaphore<K>, key: K, permits: number): Effect.Effect<void>
} = dual(3, <K>(self: PartitionedSemaphore<K>, key: K, permits: number): Effect.Effect<void> => self.take(key, permits))