Path: blob/master/node_modules/@adiwajshing/baileys/lib/Utils/make-mutex.js
1129 views
"use strict";1Object.defineProperty(exports, "__esModule", { value: true });2exports.makeKeyedMutex = exports.makeMutex = void 0;3const makeMutex = () => {4let task = Promise.resolve();5return {6mutex(code) {7task = (async () => {8// wait for the previous task to complete9// if there is an error, we swallow so as to not block the queue10try {11await task;12}13catch (_a) { }14// execute the current task15return code();16})();17// we replace the existing task, appending the new piece of execution to it18// so the next task will have to wait for this one to finish19return task;20},21};22};23exports.makeMutex = makeMutex;24const makeKeyedMutex = () => {25const map = {};26return {27mutex(key, task) {28if (!map[key]) {29map[key] = (0, exports.makeMutex)();30}31return map[key].mutex(task);32}33};34};35exports.makeKeyedMutex = makeKeyedMutex;363738