async-queue-helper

Extremely simple wrapper for async's .series and .parallel, because I got annoyed having to write var queue = [] everywhere..

async-queue

Extremely simple wrapper for async's .series and .parallel, because I got annoyed having to write var queue = [] everywhere...

Via NPM: npm install async-queue-helper

  1. Parallel:
var fs    = require('fs');
var Queue = require('async-queue-helper');
var queue = new Queue();
 
queue.add('Read license', function(next) {
    fs.readFile('../LICENSE', { encoding: 'utf-8' }, next);
});
 
queue.add('Read package', function(next) {
    fs.readFile('../package.json', { encoding: 'utf-8' }, next);
});
 
queue.parallel(function(errresultsObjresultsArr) {
    if(err) {
        console.log('An error occured.');
        console.log(err);
    } else {
        console.log('resultsObj', resultsObj);
        console.log('resultsArr', resultsArr);
    }
});
  1. Series:
var fs    = require('fs');
var Queue = require('async-queue-helper');
var queue = new Queue();
 
queue.add(function(next) {
    fs.readFile('../LICENSE', { encoding: 'utf-8' }, next);
});
 
queue.add(function(next) {
    fs.readFile('../package.json', { encoding: 'utf-8' }, next);
});
 
queue.series(function(errresultsObjresultsArr) {
    if(err) {
        console.log('An error occured.');
        console.log(err);
    } else {
        console.log('resultsObj', resultsObj);
        console.log('resultsArr', resultsArr);
    }
});

About queue.add: this method can take one or two arguments: just a function, or a name and a function. The name will be used to identify results in the resultsObj of the final callback. In first example, the LICENSE is available in resultsObj using resultsObj['Read license']. In the second example, no name is given so the license is available through resultsObj[0] or resultsArr[0].