()
| 16 | } |
| 17 | |
| 18 | public async acquire() { |
| 19 | console.debug('Acquiring lock:', this.lockName); |
| 20 | let currentLock = locks.get(this.lockName); |
| 21 | |
| 22 | while (currentLock) { |
| 23 | // Only wait if the lock hasn't expired |
| 24 | if (currentLock.expiresAt > new Date()) { |
| 25 | console.debug('Waiting for lock to expire:', this.lockName); |
| 26 | await wait(); |
| 27 | } else { |
| 28 | // Release lock since it has expired |
| 29 | this.release(); |
| 30 | } |
| 31 | |
| 32 | currentLock = locks.get(this.lockName); |
| 33 | } |
| 34 | |
| 35 | locks.set(this.lockName, { |
| 36 | expiresAt: new Date(new Date().setMilliseconds(new Date().getMilliseconds() + expirationInMilliseconds)), |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | public release() { |
| 41 | console.debug('Releasing lock:', this.lockName); |
no test coverage detected