function(cb){
   function callback(){
     cb();
   }
   asyncCallbackSpy = sandbox.spy(callback);
   async[method](items, 100500, asyncIteratorSpy, asyncCallbackSpy);
 }
Example #2
0
 properties[method] = async.proxy(function(arr, generator, cb) {
   var _iterator = async.fn(generator);
   var iterator = function(item, _cb) {
     _iterator(item, function(err, val) { _cb(val) });
   };
   _async[method](arr, iterator, function(val) {
     cb(null, val);
   });
 });
Example #3
0
					var process = function(err) {
						async[method](ids, function(i, f){
							self.node.fromId(name, i, function(err, obj){
								results.push(obj);
								f();
							});
						}, function(err){
							self.parseSet(options, results, callback);
						});
					}
Example #4
0
					db.getIndexedNodes(index, key, value, function(err, results){
						async[method](results, function(item, f){
							self.spawn(name, item, function(err, obj){
								results.push(obj);
								f();
							});
						}, function(err){
							self.parseSet(options, results, callback);
						});
					});
Example #5
0
				fromObjs: function(name, objs, options, callback) {
					if (typeof (options) === 'function') callback = options, options = {};
					var parallel = typeof(options.parallel) === 'undefined' ? true : options.parallel;
					var method = parallel ? 'each' : 'eachSeries';
					var results = [];
					async[method](objs, function(item, f){
						self.node.fromObj(name, item, function(err, obj) {
							results.push(obj);
							f();
						});
					}, function(err){
						self.parseSet(options, results, callback);
					});
				},
Example #6
0
   this.dispatch = function (config, callback) {

      var agent = new superagent.agent();
      var method = 'series';

      if (_.isPlainObject(config)) {

         agent = config.agent || agent;
         method = config.parallel ? 'parallel' : 'series';
      } else if (_.isFunction(config)) {

         callback = config;
      }

      async[method](
         _.map(this.tasks.all(), function (task) {
            
            return function (asyncCallback) {

               if (task.done()) {

                  asyncCallback(null, task.result);
               } else {

                  task.run(agent, function (taskResult) {

                     asyncCallback(null, taskResult);
                  });
               }
            };
         }),
         function (err, result) {
            
            callback(result);
         }
      );
   };
Example #7
0
 exports[ method ] = function(callback){
   async[ method ](tasks, callback)
 };
Example #8
0
 properties[method] = async.proxy(function(arr, generator, cb) {
   _async[method](arr, async.fn(generator), cb);
 });
Example #9
0
Request.prototype.execute = function execute(fn) {
  this.emit('execution', this);
  var self = this;
  this._determineDependencies();

  // Function that makes the actual request.
  function makeRequest(req) {
    Object.keys(self.client.modifiers).map(function applyModifier(name) {
      self.client.modifiers[name](req);
    });

    return function (callback, results) {
      if (req.dependencies.length > 1) {
        self.insertDependencies(req, results);
      }

      var opts = {
        uri:     req.path,
        method:  req.method,
        headers: req.headers,
        // Override default of 2 minutes for timeout.
        timeout: 30 * 1000,
        // Opt out of the default global agent pooling.
        pool:    false
      };

      if (Object.keys(req.params).length > 0) {
        opts.qs = req.params;
      }

      if (Object.keys(req.data).length > 0) {
        opts[self.client.format] = req.data;
      }

      self.emit('request', this, opts);
      var _req = request(opts, function (err, res, body) {
        if (err) {
          callback(err, body, res);
          return;
        }
        self.emit('requestComplete', this, res, body);

        if (typeof body === 'string') {
          try {
            body = JSON.parse(body);
          }
          catch (er) {
            callback(er, body, res);
            return;
          }
        }

        // Apply post modifiers
        if (req.postModifiers.length > 0) {
          var funcs = req.postModifiers.map(function(fn) {
            return _.partial(fn, body, res).bind(req);
          });
          self.emit('postModification', this, opts, res);
          async.waterfall(funcs, function (err, result) {
            self.emit('postModificationComplete', this, opts, result);
            callback(err, {
              body: result,
              response: res
            });
          });
        }
        else {
          callback(null, {
            body: body,
            response: res
          });
        }
      });

      // _req.once('error', function (err) {
      //   callback(err);
      // });
    };
  }

  // Setup structure to pass to async.
  var batch = {};
  this.requests.map(function (req, index) {
    if (self.hasDeps) {
      req.dependencies.push(makeRequest(req));
      batch[index + ''] = req.dependencies;
    }
    else {
      batch[index + ''] = makeRequest(req);
    }
  });

  // Execute requests.
  var method = this.hasDeps ? 'auto' : 'parallel';
  async[method](batch, function (err, result) {
    var response = [];
    _.forEach(result, function (itm) { response.push (itm); });
    if (response.length === 1) {
      response = response[0];
    }
    self.emit('executionComplete', this, response);
    fn(err, response, self.requests);
  });
};