Adding some debug messages
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -4,7 +4,7 @@ export default class DocumentLock {
|
||||
private locks = new Map<string, (() => void)[]>();
|
||||
|
||||
getLocks() {
|
||||
return Array.from(this.locks.keys())
|
||||
return Array.from(this.locks.keys());
|
||||
}
|
||||
|
||||
async lock(collection: string = "", document: string = "") {
|
||||
@ -12,17 +12,18 @@ export default class DocumentLock {
|
||||
let key = collection + "/" + document;
|
||||
let l = this.locks.get(key);
|
||||
if (l)
|
||||
await new Promise(resolve => { l.push(resolve); this.locks.set(key, l) });
|
||||
await new Promise((resolve) => {
|
||||
l.push(resolve);
|
||||
this.locks.set(key, l);
|
||||
});
|
||||
else {
|
||||
l = [];
|
||||
this.locks.set(key, l);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (l.length > 0)
|
||||
setImmediate(() => l.shift()());
|
||||
else
|
||||
this.locks.delete(key)
|
||||
}
|
||||
if (l.length > 0) setImmediate(() => l.shift()());
|
||||
else this.locks.delete(key);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user