Sequence.js

About stack size

Working: Big multi step

let stepCounter = 0;
let stepFunc = (cb) => {
    stepCounter += 1;
    cb();
};

let arr = Array.from(Array(100000), (undefined, i) => { return stepFunc; });

(new Sequence())
.step(arr)
.run([]).then(() => { console.log(stepCounter); });

Working: High step count

let stepFunc = ([counter]) => {
    return counter + 1;
};

let arr = Array.from(Array(100000), (undefined, i) => { return stepFunc });

let sqnc = new Sequence();
arr.forEach(sqnc.step);
sqnc.run([0]).then(([counter]) => { console.log(counter); });

Working: Synchronous callbacks

let stepFunc = ([counter]) => {
    return (cb) => {
        // here we are using cb even if we are not async
        // normally it would cause stack size errors
        cb(counter + 1);
    };
};

let arr = Array.from(Array(100000), (undefined, i) => { return stepFunc });

let sqnc = new Sequence();
arr.forEach(sqnc.step);
sqnc.run([0]).then(([counter]) => { console.log(counter); });