* Acquire the lock * * @returns A release function to call when done
()
| 691 | * @returns A release function to call when done |
| 692 | */ |
| 693 | async acquire(): Promise<() => void> { |
| 694 | while (this.locked) { |
| 695 | await new Promise<void>((resolve) => { |
| 696 | this.waitQueue.push(resolve); |
| 697 | }); |
| 698 | } |
| 699 | |
| 700 | this.locked = true; |
| 701 | |
| 702 | return () => { |
| 703 | this.locked = false; |
| 704 | const next = this.waitQueue.shift(); |
| 705 | if (next) { |
| 706 | next(); |
| 707 | } |
| 708 | }; |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Execute a function while holding the lock |
no test coverage detected