()
| 37 | } |
| 38 | |
| 39 | async acquire(): Promise<() => void> { |
| 40 | // Only count as waiting if the permit won't be granted immediately. |
| 41 | const willQueue = this.sem.isLocked() |
| 42 | const gen = this._generation |
| 43 | if (willQueue) this._waiting++ |
| 44 | try { |
| 45 | const [, release] = await this.sem.acquire() |
| 46 | if (willQueue && gen === this._generation) this._waiting-- |
| 47 | return release |
| 48 | } catch (e) { |
| 49 | if (willQueue && gen === this._generation) this._waiting-- |
| 50 | throw e |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Rejects all queued waiters and resets the waiting count to 0. |
no outgoing calls
no test coverage detected