UNPKG

@lcap/nasl

Version:

NetEase Application Specific Language

28 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withQueueExecute = void 0; const stateMap = new Map(); /** * 强制队列执行 * * @description 所有使用此修饰器的方法,都会被强制使用队列执行,先调用的先执行。在前面的函数执行完毕之前,后面的函数是不会执行的。 * @param {string} name 队列名称,用于区分不同的执行队列 */ function withQueueExecute(name) { const handler = (target, methodName, descriptor) => { const oldMethod = descriptor.value; descriptor.value = function (...args) { const oldState = stateMap.get(name); const newState = oldState.then(() => oldMethod.call(this, ...args)); stateMap.set(name, newState); return newState; }; return descriptor; }; if (!stateMap.has(name)) { stateMap.set(name, Promise.resolve()); } return handler; } exports.withQueueExecute = withQueueExecute; //# sourceMappingURL=promise.js.map