Fast execution of an array of functions with the same value as input that can be altered.
Install
npm i fast-iterator --save
Usage
const fast = require('fast-iterator')fast( [fn1, fn2, fn3], // the array of functions to execute { context: true } // a custom context for every function)( iterator.bind({ a: 'a', b: 'b' }), // an iterator function to pass custom parameters { hello: 'world' }, // the value to update done // the function to call once the work has been done)function fn1 (a, b, result, done) { console.log(a, b, result, this) done(null, { ciao: 'mondo' })}function fn2 (a, b, result, done) { console.log
Output:
a b { hello: 'world' } { context: true }a b { ciao: 'mondo' } { context: true }a b { winter: 'is coming' } { context: true }{ winter: 'has come' } { context: true }
If you need to release the internal Object holder for performances reasons, you can call the fourth parameter of the iterator: release.
function iterator (fn, result, done, release) { if (someCondition) return release() return fn(this.a, this.b, result, done)}