control flow library for parallel async functions; it invokes the callback with the aggregated results or an error
control flow library for parallel async functions; it invokes the callback with the aggregated results or an error
Specify callback to run after all functions have completed at the end:
var parallelize = require('parallelize');
var next = parallelize();
fs.readFile(file1, next());
fs.readFile(file2, next());
next(function displayResults(err, results) {
if (err) { throw err; }
// `results` array with data in the order which the async fns were called
console.log(file1 + ' contents', results[0]);
console.log(file2 + ' contents', results[1]);
});
If you'd prefer to have a results object instead of an array check the results-object.js
example for more details.
I wanted something similar to after that aggregates results. Note that I did not want to pass an array of functions like async does. There might be other libraries with similar approaches in the NPM registry, but nevertheless it was fun to create this one.
The function returned by the module should wrap all your callbacks. It has two roles:
With npm do:
npm install parallelize
With npm do:
npm test