* Acquire the lock * * @returns A release function to call when done
()
| 382 | * @returns A release function to call when done |
| 383 | */ |
| 384 | async acquire(): Promise<() => void> { |
| 385 | while (this.locked) { |
| 386 | await new Promise<void>((resolve) => { |
| 387 | this.waitQueue.push(resolve); |
| 388 | }); |
| 389 | } |
| 390 | |
| 391 | this.locked = true; |
| 392 | |
| 393 | return () => { |
| 394 | this.locked = false; |
| 395 | const next = this.waitQueue.shift(); |
| 396 | if (next) { |
| 397 | next(); |
| 398 | } |
| 399 | }; |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Execute a function while holding the lock |
no outgoing calls
no test coverage detected