summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <aearly@fluid.com>2015-06-01 00:32:53 -0700
committerAlexander Early <aearly@fluid.com>2015-06-01 00:32:53 -0700
commit6741e6ced59f0c57f88a4deb2b3729a05981df6f (patch)
tree04f5c3c0d79e37ab1c6ba891a7cd59e793e6de5b
parentba53a8ad87b839550dc8a648afb17d904e37d207 (diff)
downloadasync-6741e6ced59f0c57f88a4deb2b3729a05981df6f.tar.gz
seq callback is now optional. closes #618
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/async.js13
-rwxr-xr-xtest/test-async.js20
3 files changed, 31 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d637ab4..83c1230 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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)
diff --git a/lib/async.js b/lib/async.js
index 58b11d9..abc1f7b 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -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) {
@@ -822,7 +822,7 @@
_arrayEach(data, function(task) {
var item = {
data: task,
- callback: typeof callback === 'function' ? callback : noop
+ callback: callback || noop
};
if (pos) {
@@ -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];
diff --git a/test/test-async.js b/test/test-async.js
index 2fe11bd..670d14a 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -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({