Adding some debug messages
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Fabian Stamm
2020-06-17 22:40:23 +02:00
parent 16e5753fc6
commit 794820e1d3
3 changed files with 181 additions and 134 deletions

View File

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