* Acquires a permit for the callback immediately when one is available or * queues the callback until another task releases its permit. * @param {() => void} callback function block to capture and run * @returns {void}
(callback)
| 32 | * @returns {void} |
| 33 | */ |
| 34 | acquire(callback) { |
| 35 | if (this.available > 0) { |
| 36 | this.available--; |
| 37 | callback(); |
| 38 | } else { |
| 39 | this.waiters.push(callback); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Releases a permit and schedules the next waiting callback, if any. |
no test coverage detected