1.0.1 • Published 9 years ago

collect-parallel v1.0.1

Weekly downloads
6
License
-
Repository
github
Last release
9 years ago

collect-parallel

Run N things in parallel and collect results

Example

var collectParallel = require("collect-parallel/array");

collectParallel([
    50,
    100,
    200
], function doTimer(value, i, callback) {
    setTimeout(onTimer, value);

    function onTimer() {
        callback(null, value);
    }
}, function onResults(err, results) {
    // err is always `null`
    // results is an array;
    // it contains `Result()` objects with `err` and `value`
    console.log(results[1].value);
});

Example object

var collectParallelObject = require("collect-parallel/object");

collectParallelObject({
    50: 50,
    100: 100,
    200: 200
}, function doTimer(value, i, callback) {
    setTimeout(onTimer, value);

    function onTimer() {
        callback(null, value);
    }
}, function onResults(err, results) {
    // err is always `null`
    // results is an object;
    // it contains `Result()` objects with `err` and `value`
    console.log(results['100'].value);
});

Installation

npm install collect-parallel

Tests

npm test

Contributors

  • Raynos

MIT Licensed