array-series
Advanced tools
Comparing version 0.1.1 to 0.1.2
22
index.js
@@ -11,12 +11,18 @@ module.exports = function series(fns, context, callback) { | ||
var length = fns.length | ||
var length = fns && fns.length | ||
if (!length) return callback(); | ||
var index = 0 | ||
fns = fns.slice(0) | ||
var call = context ? function () { | ||
fns[index].call(context, next) | ||
} : function () { | ||
fns[index](next) | ||
var call = context | ||
? function () { | ||
fns.length | ||
? fns.shift().call(context, next) | ||
: callback() | ||
} | ||
: function () { | ||
fns.length | ||
? fns.shift()(next) | ||
: callback() | ||
} | ||
@@ -26,5 +32,3 @@ call() | ||
function next(err) { | ||
if (err || ++index === length) return callback(err); | ||
call() | ||
err ? callback(err) : call() | ||
} | ||
@@ -31,0 +35,0 @@ } |
{ | ||
"name": "array-series", | ||
"description": "Call an array of asynchronous functions in series", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"scripts": { | ||
@@ -6,0 +6,0 @@ "test": "node test" |
@@ -86,2 +86,4 @@ var assert = require('assert') | ||
assert.equal(o, undefined) | ||
}) | ||
}) | ||
console.log('Array series tests pass!') |
4037
115