UNPKG

phasic

Version:

Run functions in phases. Useful for load and performance testing

24 lines (23 loc) 815 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.runPhases = void 0; function runPhase(phase, func) { return new Promise((resolve, reject) => { const phaseResults = []; const phaseTimer = setInterval(() => [...Array(phase.arrivalRate).keys()].forEach(() => phaseResults.push(func())), 1000); setTimeout(() => { clearInterval(phaseTimer); resolve(Promise.allSettled(phaseResults)); }, (phase.duration * 1000) + 1000); }); } function runPhases(phases, func) { return new Promise(async (resolve, reject) => { const results = []; for (const phase of phases) { results.push(await runPhase(phase, func)); } resolve(results.flat()); }); } exports.runPhases = runPhases;