drainer

Queue and drain an array of functions in series

drainer

Queue and drain an array of functions in series.

npm install drainer --save
var drainer = require('drainer');
 
drainer([
  function (next) {
    next();
  },
  function (next) {
    next(null, 'some value');
  },
  function (arg1next) {
    // arg1 == 'some value' 
    next(null, 'final value');
  }
], function (errfinalValue) {
  // finalValue == 'final value'; 
});

Each function in the array recieves a callback, next(), to call when done. If only one argument is passed into that callback, it will assume that it is an error, exit the chain, and call the final callback with the error.

If you have arguments that you want to pass to each method without explicitly passing them each method, you can easily do that like this:

var drainer = require('drainer');
var drain = drainer([
  function (defaultArg1defaultArg2next) {
    next();
  },
  function (defaultArg1defaultArg2next) {
    next();
  }
]);
 
drainer('defaultArg1', 'defaultArg2', function (errdefaultArg1defaultArg2) {
  
});

If you call the next() callback in the queued function with the first argument as null, any argument following will be passed to the next function in the queue.

The final callback will recieve any values passed from the last function in the function queue.

npm install
npm test