[Pkg-javascript-commits] [node-async] 259/480: Merge remote branch 'timoxley/master'

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:32 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 712d06c03972dda89f1a1f4af561b6e2a8d488d2
Merge: 418ae9f f128d3d
Author: Caolan McMahon <caolan at caolanmcmahon.com>
Date:   Thu Jan 31 15:21:19 2013 +0000

    Merge remote branch 'timoxley/master'
    
    Conflicts:
    	README.md
    	lib/async.js
    	test/test-async.js

 README.md          | 39 +++++++++++++++++++++++++++++-
 lib/async.js       | 17 +++++++++++++
 test/test-async.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 125 insertions(+), 1 deletion(-)

diff --cc README.md
index 5c3351b,45f7dfc..6338258
--- a/README.md
+++ b/README.md
@@@ -1079,15 -902,48 +1081,50 @@@ __Arguments_
  
  __Example__
  
 -    var call_order = [];
 -    async.nextTick(function(){
 -        call_order.push('two');
 -        // call_order now equals ['one','two]
 -    });
 -    call_order.push('one')
 +```js
 +var call_order = [];
 +async.nextTick(function(){
 +    call_order.push('two');
-     // call_order now equals ['one','two]
++    // call_order now equals ['one','two']
 +});
 +call_order.push('one')
 +```
  
+ <a name="times" />
+ ### times(n, callback)
+ 
+ Calls the callback n times and accumulates results in the same manner
+ you would use with async.map.
+ 
+ __Arguments__
+ 
+ * n - The number of times to run the function.
+ * callback - The function to call n times.
+ 
+ __Example__
+     // Pretend this is some complicated async factory
+     var createUser = function(id, callback) {
+       callback(null, {
+         id: 'user' + id
+       })
+     }
+     // generate 5 users
+     async.times(5, function(n, next){
+         createUser(n, function(err, user) {
+           next(err, user)
+         })
+     }, function(err, users) {
+       // we should now have 5 users
+     });
+ 
+ <a name="timesSeries" />
+ ### timesSeries(n, callback)
+ 
+ The same as times only the iterator is applied to each item in the array in
+ series. The next iterator is only called once the current one has completed
+ processing. The results array will be in the same order as the original.
+ 
+ 
  ## Utils
  
  <a name="memoize" />
diff --cc lib/async.js
index 7e8d2d0,f83a56b..e8520ee
--- a/lib/async.js
+++ b/lib/async.js
@@@ -881,22 -684,22 +881,39 @@@
      async.unmemoize = function (fn) {
        return function () {
          return (fn.unmemoized || fn).apply(null, arguments);
 -      }
 +      };
 +    };
 +
++    async.times = function (count, iterator, callback) {
++        var counter = [];
++        for (var i = 0; i < count; i++) {
++            counter.push(i);
++        }
++        return async.map(counter, iterator, callback);
+     };
+ 
 -    async.times = function(count, iterator, callback) {
 -      var counter = []
 -      for (var i = 0; i < count; i++) {
 -        counter.push(i)
 -      }
 -      return async.map(counter, iterator, callback)
++    async.timesSeries = function (count, iterator, callback) {
++        var counter = [];
++        for (var i = 0; i < count; i++) {
++            counter.push(i);
++        }
++        return async.mapSeries(counter, iterator, callback);
++    };
++
++
 +    // AMD / RequireJS
 +    if (typeof define !== 'undefined' && define.amd) {
 +        define('async', [], function () {
 +            return async;
 +        });
      }
 -    async.timesSeries = function(count, iterator, callback) {
 -      var counter = []
 -      for (var i = 0; i < count; i++) {
 -        counter.push(i)
 -      }
 -      return async.mapSeries(counter, iterator, callback)
 +    // Node.js
 +    else if (typeof module !== 'undefined' && module.exports) {
 +        module.exports = async;
 +    }
 +    // included directly via <script> tag
 +    else {
 +        root.async = async;
      }
  
  }());

-- 
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