UNPKG

vulcain-corejs

Version:
43 lines (41 loc) 1.39 kB
"use strict"; class Semaphore { constructor(maxExecution, maxFallback) { this.maxExecution = maxExecution; this.maxFallback = maxFallback; this.currentExecution = 0; this.currentFallback = 0; } canExecuteCommand() { this.currentExecution++; return this.maxExecution === 0 || this.currentExecution <= this.maxExecution; } releaseExecutionCommand() { this.currentExecution--; } canExecuteFallback() { this.currentFallback++; return this.currentFallback === 0 || this.currentExecution <= this.maxFallback; } releaseFallback() { this.currentFallback--; } } exports.Semaphore = Semaphore; class SemaphoreFactory { static getOrCreate(info) { let previouslyCached = SemaphoreFactory.semaphores.get(info.commandName); if (previouslyCached) { return previouslyCached; } let semaphore = new Semaphore(info.executionIsolationSemaphoreMaxConcurrentRequests.value, info.fallbackIsolationSemaphoreMaxConcurrentRequests.value); SemaphoreFactory.semaphores.set(info.commandName, semaphore); return semaphore; } static resetCache() { SemaphoreFactory.semaphores.clear(); } } SemaphoreFactory.semaphores = new Map(); exports.SemaphoreFactory = SemaphoreFactory; //# sourceMappingURL=semaphore.js.map