JezK
Edit File: mutex.js
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var lockPromises = new Map(); /** * Acquires a mutex lock over the given key. If the lock can't be acquired, it waits until it's available. * @param key Key to get the lock for. * @return {Promise.<Function>} A Promise that resolves when the lock is acquired, with the function that * must be called to release the lock. */ var _default = function _default(key) { var unlockNext; var willLock = new Promise(function (resolve) { return unlockNext = resolve; }); var lockPromise = lockPromises.get(key) || Promise.resolve(); var willUnlock = lockPromise.then(function () { return unlockNext; }); lockPromises.set(key, lockPromise.then(function () { return willLock; })); return willUnlock; }; exports["default"] = _default; //# sourceMappingURL=mutex.js.map