MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / acquire

Method acquire

lib/interfaces/locker.ts:18–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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);

Callers 3

recalculateMonthBudgetsFunction · 0.95
crawlMethod · 0.95

Calls 4

releaseMethod · 0.95
waitFunction · 0.85
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected