* Acquire the lock * * @returns A release function to call when done
()
| 717 | * @returns A release function to call when done |
| 718 | */ |
| 719 | async acquire(): Promise<() => void> { |
| 720 | while (this.locked) { |
| 721 | await new Promise<void>((resolve) => { |
| 722 | this.waitQueue.push(resolve); |
| 723 | }); |
| 724 | } |
| 725 | |
| 726 | this.locked = true; |
| 727 | |
| 728 | return () => { |
| 729 | this.locked = false; |
| 730 | const next = this.waitQueue.shift(); |
| 731 | if (next) { |
| 732 | next(); |
| 733 | } |
| 734 | }; |
| 735 | } |
| 736 | |
| 737 | /** |
| 738 | * Execute a function while holding the lock |
no test coverage detected