Nutritious Pomegranate Muffins
    Have ideas to improve npm?Join in the discussion! »

    async-queue-helper

    0.1.4 • Public • Published

    async-queue

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

    Installation

    Via NPM: npm install async-queue-helper

    Usage

    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(err, resultsObj, resultsArr) {
        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(err, resultsObj, resultsArr) {
        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].

    Install

    npm i async-queue-helper

    DownloadsWeekly Downloads

    2

    Version

    0.1.4

    License

    MIT

    Last publish

    Collaborators

    • avatar