MCPcopy Create free account
hub / github.com/Effect-TS/effect / withPermits

Method withPermits

packages/effect/src/Semaphore.ts:287–307  ·  view source on GitHub ↗
(n: number)

Source from the content-addressed store, hash-verified

285 }
286
287 withPermits(n: number) {
288 return <A, E, R>(self: Effect.Effect<A, E, R>) =>
289 internal.uninterruptibleMask((restore) => {
290 const acquire: Effect.Effect<A, E, R> = internal.suspend(() => {
291 if (this.free < n) {
292 const wait = waitForPermits(this, n, internal.void)
293 return internal.flatMap(restore(wait), () => acquire)
294 }
295 this.taken += n
296 return internal.onExitPrimitive(
297 restore(self),
298 () => {
299 this.releaseUnsafe(internal.getCurrentFiber()!, n)
300 return undefined
301 },
302 true
303 )
304 })
305 return acquire
306 })
307 }
308
309 readonly withPermit = this.withPermits(1)
310

Callers 1

SemaphoreImplClass · 0.95

Calls 2

releaseUnsafeMethod · 0.95
waitForPermitsFunction · 0.85

Tested by

no test coverage detected