UNPKG

@sentzunhat/zacatl

Version:

A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.

39 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeCommands = void 0; const runner_1 = require("./runner"); const types_1 = require("./types"); const executeCommands = (commands, policyInput = {}) => { const policy = types_1.runnerPolicySchema.parse(policyInput); if (commands.length === 0) { return Promise.resolve([]); } return new Promise((resolve, reject) => { const results = new Array(commands.length); let nextIndex = 0; let active = 0; const dispatch = () => { while (active < policy.maxConcurrency && nextIndex < commands.length) { const capturedIndex = nextIndex++; active++; (0, runner_1.runCommand)(commands[capturedIndex], policy) .then((result) => { results[capturedIndex] = result; }) .catch(reject) .finally(() => { active--; if (nextIndex < commands.length) { dispatch(); } else if (active === 0) { resolve(results); } }); } }; dispatch(); }); }; exports.executeCommands = executeCommands; //# sourceMappingURL=execute-commands.js.map