mirror of https://github.com/TriliumNext/Notes
Merge remote-tracking branch 'origin/stable'
commit
67cce5f817
@ -0,0 +1,28 @@
|
|||||||
|
export default class Mutex {
|
||||||
|
constructor() {
|
||||||
|
this.current = Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @returns {Promise} */
|
||||||
|
lock() {
|
||||||
|
let resolveFun;
|
||||||
|
const subPromise = new Promise(resolve => resolveFun = () => resolve());
|
||||||
|
// Caller gets a promise that resolves when the current outstanding lock resolves
|
||||||
|
const newPromise = this.current.then(() => resolveFun);
|
||||||
|
// Don't allow the next request until the new promise is done
|
||||||
|
this.current = subPromise;
|
||||||
|
// Return the new promise
|
||||||
|
return newPromise;
|
||||||
|
};
|
||||||
|
|
||||||
|
async runExclusively(cb) {
|
||||||
|
const unlock = await this.lock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await cb();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1 +1 @@
|
|||||||
module.exports = { buildDate:"2022-02-02T21:38:21+01:00", buildRevision: "0917fc8be171253449219cf29c0e603ac29eb26e" };
|
module.exports = { buildDate:"2022-02-09T22:52:36+01:00", buildRevision: "23daaa2387a0655685377f0a541d154aeec2aae8" };
|
||||||
|
|||||||
Loading…
Reference in New Issue