util/async.js
function(items, iterator, done) {
    done = done || function() {};
    var results = [];
    var failure = false;
    var expected = items.length;
    var actual = 0;
    var createIntermediary = function(index) {
      return function(err, result) {
        // Return if we found a failure anywhere.
        // We can't stop execution of functions since they've already
        // been fired off; but we can prevent excessive handling of callbacks.
        if (failure != false) {
          return;
        }

        if (err != null) {
          failure = true;
          done(err, result);
          return;
        }

        actual += 1;

        if (actual == expected) {
          done(null, results);
        }
      };
    };

    for (var i = 0; i < items.length; i++) {
      var item = items[i];
      iterator(item, createIntermediary(i));
    }

    if (items.length == 0) {
      done(null, []);
    }
  }
function(items, iterator, done) {
    done = done || function() {};
    var results = [];
    var failure = false;
    var expected = items.length;
    var actual = 0;
    var createIntermediary = function(index) {
      return function(err, result) {
        // Return if we found a failure anywhere.
        // We can't stop execution of functions since they've already
        // been fired off; but we can prevent excessive handling of callbacks.
        if (failure != false) {
          return;
        }

        if (err != null) {
          failure = true;
          done(err, result);
          return;
        }

        actual += 1;

        if (actual == expected) {
          done(null, results);
        }
      };
    };

    for (var i = 0; i < items.length; i++) {
      var item = items[i];
      iterator(item, createIntermediary(i));
    }

    if (items.length == 0) {
      done(null, []);
    }
  }
function ( items , iterator , done ) { done = done || function ( ) { } ; var results = [ ] ; var failure = false ; var expected = items . length ; var actual = 0 ; var createIntermediary = function ( index ) { return function ( err , result ) { // Return if we found a failure anywhere. // We can't stop execution of functions since they've already // been fired off; but we can prevent excessive handling of callbacks. if ( failure != false ) { return ; } if ( err != null ) { failure = true ; done ( err , result ) ; return ; } actual += 1 ; if ( actual == expected ) { done ( null , results ) ; } } ; } ; for ( var i = 0 ; i < items . length ; i ++ ) { var item = items [ i ] ; iterator ( item , createIntermediary ( i ) ) ; } if ( items . length == 0 ) { done ( null , [ ] ) ; } }
Works the same as async.map
Works the same as async . map