Skip to content

Commit

Permalink
seq callback is now optional. closes #618
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Early committed Jun 1, 2015
1 parent ba53a8a commit 6741e6c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ New Features:
- Added `ensureAsync` - A wrapper that ensures an async function calls its callback on a later tick. (#769)
- Optimized `map`, `eachOf`, and `waterfall` families of functions
- Passing a `null` or `undefined` array to `map`, `each`, `parallel` and families will be treated as an empty array (#667).
- The callback is not optional for the composed results of `compose` and `seq`. (#618)
- Reduced file size by 4kb, (minified version by 1kb)
- Added code coverage through `nyc` and `coveralls` (#768)

Expand Down
13 changes: 10 additions & 3 deletions lib/async.js
Expand Up @@ -335,7 +335,7 @@
}

function _asyncMap(eachfn, arr, iterator, callback) {
callback = callback || noop;
callback = _once(callback || noop);
var results = [];
eachfn(arr, function (value, index, callback) {
iterator(value, function (err, v) {
Expand Down Expand Up @@ -822,7 +822,7 @@
_arrayEach(data, function(task) {
var item = {
data: task,
callback: typeof callback === 'function' ? callback : noop
callback: callback || noop
};

if (pos) {
Expand Down Expand Up @@ -1077,7 +1077,14 @@
return function () {
var that = this;
var args = _baseSlice(arguments);
var callback = args.pop();

var callback = args.slice(-1)[0];
if (typeof callback == 'function') {
args.pop();
} else {
callback = noop;
}

async.reduce(fns, args, function (newargs, fn, cb) {
fn.apply(that, newargs.concat([function () {
var err = arguments[0];
Expand Down
20 changes: 20 additions & 0 deletions test/test-async.js
Expand Up @@ -387,6 +387,26 @@ exports['seq binding'] = function (test) {
});
};

exports['seq without callback'] = function (test) {
test.expect(2);
var testcontext = {name: 'foo'};

var add2 = function (n, cb) {
test.equal(this, testcontext);
setTimeout(function () {
cb(null, n + 2);
}, 50);
};
var mul3 = function () {
test.equal(this, testcontext);
setTimeout(function () {
test.done();
}, 15);
};
var add2mul3 = async.seq(add2, mul3);
add2mul3.call(testcontext, 3);
};

exports['auto'] = function(test){
var callOrder = [];
async.auto({
Expand Down

0 comments on commit 6741e6c

Please sign in to comment.