(n: number)
| 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 |
no test coverage detected