chrono-forge
Version:
A comprehensive framework for building resilient Temporal workflows, advanced state management, and real-time streaming activities in TypeScript. Designed for a seamless developer experience with powerful abstractions, dynamic orchestration, and full cont
24 lines (23 loc) • 852 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mutex = Mutex;
const async_mutex_1 = require("async-mutex");
const instanceMutexMap = new Map();
function Mutex(mutexName = 'execute') {
return (target, propertyKey, descriptor) => {
const originalMethod = descriptor.value;
descriptor.value = async function (...args) {
let mutexMap = instanceMutexMap.get(this);
if (!mutexMap) {
mutexMap = new Map();
instanceMutexMap.set(this, mutexMap);
}
let mutex = mutexMap.get(mutexName);
if (!mutex) {
mutex = new async_mutex_1.Mutex();
mutexMap.set(mutexName, mutex);
}
return mutex.runExclusive(() => originalMethod.apply(this, args));
};
};
}