[Pkg-javascript-commits] [node-async] 148/480: Allow `forEach*` functions to be called with no callback

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:21 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository node-async.

commit c82e885c3f4cd0bce2f02b0d6a46774fa78c89fc
Author: Maciej Małecki <maciej.malecki at notimplemented.org>
Date:   Tue Feb 21 02:28:57 2012 +0100

    Allow `forEach*` functions to be called with no callback
    
    Tests included.
---
 lib/async.js       |  3 +++
 test/test-async.js | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/lib/async.js b/lib/async.js
index 0bcd80d..a607e6c 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -89,6 +89,7 @@
     }
 
     async.forEach = function (arr, iterator, callback) {
+        callback = callback || function () {};
         if (!arr.length) {
             return callback();
         }
@@ -110,6 +111,7 @@
     };
 
     async.forEachSeries = function (arr, iterator, callback) {
+        callback = callback || function () {};
         if (!arr.length) {
             return callback();
         }
@@ -135,6 +137,7 @@
     };
     
     async.forEachLimit = function (arr, limit, iterator, callback) {
+        callback = callback || function () {};
         if (!arr.length || limit <= 0) {
             return callback(); 
         }
diff --git a/test/test-async.js b/test/test-async.js
index e51cea0..ff4b749 100644
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -37,6 +37,12 @@ function detectIterator(call_order, x, callback) {
     }, x*25);
 }
 
+function forEachNoCallbackIterator(test, x, callback) {
+    test.equal(x, 1);
+    callback();
+    test.done();
+}
+
 function getFunctionsObject(call_order) {
     return {
         one: function(callback){
@@ -514,6 +520,10 @@ exports['forEach error'] = function(test){
     setTimeout(test.done, 50);
 };
 
+exports['forEach no callback'] = function(test){
+    async.forEach([1], forEachNoCallbackIterator.bind(this, test));
+};
+
 exports['forEachSeries'] = function(test){
     var args = [];
     async.forEachSeries([1,3,2], forEachIterator.bind(this, args), function(err){
@@ -546,6 +556,10 @@ exports['forEachSeries error'] = function(test){
     setTimeout(test.done, 50);
 };
 
+exports['forEachSeries no callback'] = function(test){
+    async.forEachSeries([1], forEachNoCallbackIterator.bind(this, test));
+};
+
 exports['forEachLimit'] = function(test){
     var args = [];
     var arr = [0,1,2,3,4,5,6,7,8,9];
@@ -617,6 +631,10 @@ exports['forEachLimit error'] = function(test){
     setTimeout(test.done, 25);
 };
 
+exports['forEachLimit no callback'] = function(test){
+    async.forEachLimit([1], 1, forEachNoCallbackIterator.bind(this, test));
+};
+
 exports['map'] = function(test){
     var call_order = [];
     async.map([1,3,2], mapIterator.bind(this, call_order), function(err, results){

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git



More information about the Pkg-javascript-commits mailing list