How to use the async.parallel function in async

To help you get started, we’ve selected a few async examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EdgeVerve / oe-cloud / common / mixins / model-validations.js View on Github external
log.debug(options, 'Data posted is not valid');
                // Add error to the response object
                getError(self, errArr);
                // done(valid);
              }
              // running custom validations of model(written in model js file) if any
              if (Model.customValidations || inst.__data.customValidations) {
                log.trace(options, 'executing custom validations for model');
                var customValArr = [];
                var custValidations = inst.__data.customValidations || [];
                delete inst.__data.customValidations;
                custValidations = custValidations.concat(Model.customValidations || []);
                custValidations.forEach(function customValidationForEachCb(customValidation) {
                  customValArr.push(async.apply(customValidation, inst.__data, context));
                });
                async.parallel(customValArr, function customModelValidationsAsyncParallelElseCb(err, customResults) {
                  if (err) {
                    customResults.push(err);
                  }
                  // Add error to the response object
                  customResults = [].concat.apply([], customResults);
                  var custErrArr = customResults.filter(function modelValidationAsyncParalllelCustomErrCb(d) {
                    return d !== null && typeof d !== 'undefined';
                  });
                  // inst.errors will have custom errors if any
                  if ((custErrArr && custErrArr.length > 0) || inst.errors) {
                    valid = false;
                    getError(self, custErrArr);
                  }
                  done(valid);
                });
              } else {
github adblockradio / adblockradio / predictor.js View on Github external
} catch (e) {
				log.warn("could not write to decoder. err=" + e);
			}
		}

		if (!dataObj.newSegment) return out();

		// actions on new segment
		//log.debug("dl+decoder pause");

		this.dl.pause();
		this.decoder.stdout.pause();

		// TODO: do the hotlist search only if mlPredictor is unsure?

		async.parallel([

			function(cb) {
				if (!self.config.enablePredictorMl || !self.mlPredictor.ready) return setImmediate(cb);
				self.mlPredictor.predict(function(err, data) {
					if (!err && data && self.listener.writable) {
						self.listener.write({ type: "ml", data });
					} else {
						log.warn("skip ml result because err=" + err + " data=" + JSON.stringify(data) + " writable=" + self.listener.writable);
					}
					cb(err);
				});
			},
			function(cb) {
				if (!self.config.enablePredictorHotlist) return setImmediate(cb);
				self.hotlist.onFingers(function(err, data) {
					if (!err && data && self.listener.writable) {
github mozillascience / CitationCore / sourceHandlers / bitBucket.js View on Github external
fetch(callback) {
    async.parallel([
      // Fetches version data on the Repo
      (cb) => {
        this._sendApiRequest(this.url, `${this.repoPath}/versions`, cb);
      },
      // Fetches the author data
      (cb) => {
        this._getAllCommits(this.url, `${this.repoPath}/commits`, {}, cb);
      },
      // Fetch General data
      (cb) => {
        this._sendApiRequest(this.url, `${this.repoPath}`, cb);
      },
    ], (error, results) => {
      if (error === null) {
        const sourceData = new SourceData();
        // General info
github mallocator / Elasticsearch-Exporter / drivers / mongodb.driver.js View on Github external
getSourceStats(env, callback) {
        let stats = {
            cluster_status: 'Red',
            docs: {
                total: 0
            },
            databases: {}
        };

        async.parallel([
            callback => {
                this.source.getDb(env.options.source, (err, db) => {
                    if (err) {
                        return callback(err);
                    }
                    db.admin().serverStatus((err, info) => {
                        if (err) {
                            return callback(err);
                        }
                        stats.version = info.version;
                        stats.cluster_status = 'Green';
                        callback();
                    });
                });
            },
            callback => {
github wayneashleyberry / wunderline / wunderline-export.js View on Github external
function(list, complete) {
      async.parallel(
        [
          function getTasks(cb) {
            api(
              { url: "/tasks", qs: { list_id: list.id, completed: false } },
              function(err, res, body) {
                showProgress();
                cb(err, body);
              }
            );
          },
          function getCompletedTasks(cb) {
            api(
              { url: "/tasks", qs: { list_id: list.id, completed: true } },
              function(err, res, body) {
                showProgress();
                cb(err, body);
github opencolor-tools / sketch-opencolor / gulpfile.js View on Github external
gulp.task('prepare-folders',function(callback) {
    async.parallel({
        build: function(callback) {
            fse.ensureDir(path.join(__dirname,'build'),callback);
        },
        dist: function(callback) {
            fse.ensureDir(path.join(__dirname,'dist'),callback);
        }
    },callback);
});
github edutec / Snap4Arduino-old-huge / modules / gnu / node_modules / serialport / node_modules / node-pre-gyp / node_modules / request / node_modules / form-data / lib / form_data.js View on Github external
FormData.prototype.getLength = function(cb) {
  var knownLength = this._overheadLength + this._valueLength;

  if (this._streams.length) {
    knownLength += this._lastBoundary().length;
  }

  if (!this._lengthRetrievers.length) {
    process.nextTick(cb.bind(this, null, knownLength));
    return;
  }

  async.parallel(this._lengthRetrievers, function(err, values) {
    if (err) {
      cb(err);
      return;
    }

    values.forEach(function(length) {
      knownLength += length;
    });

    cb(null, knownLength);
  });
};
github godaddy / node-cluster-service / lib / net-servers.js View on Github external
function netServersClose(cb) {
  var tasks = [];

  for (var id in cservice.locals.net.servers) {
    var server = cservice.locals.net.servers[id];
    if (!server.cservice || server.cservice.isReady === false)
      continue;

    tasks.push(createWaitForCloseTask(server));
  }
  
  if (tasks.length === 0) {
    return cb();
  }

  async.parallel(tasks, cb);
}
github EdgeVerve / oe-cloud / lib / service-personalizer.js View on Github external
case 'customFunction':
          arr.push(async.apply(addCustomFunction, ctx, p13nRule[instruction]));
          break;
        case 'httpPostFunction':
          arr.push(async.apply(addHttpPostFunction, ctx, p13nRule[instruction]));
          break;
        case 'mask':
          arr.push(async.apply(maskFields, ctx, p13nRule[instruction]));
          break;
        default:
      }
    }
  }

  log.debug(ctx.req.callContext, 'returning updated context - ', ctx);
  async.parallel(arr, function applyPersonalizationRuleAsyncParallelFn(err, results) {
    if (err) {
      callback(err);
    }
    callback();
  });
};
github vpapakir / uptime-openshift / fixtures / populate.js View on Github external
var createFixtureChecks = function(callback) {
  async.parallel([
    function(cb) { createDummyCheck(99.95, 'Top Quality', ['good', 'all'], cb); },
    function(cb) { createDummyCheck(99.85, 'Good Quality', ['good', 'all'], cb); },
    function(cb) { createDummyCheck(99, 'Neun und neunzig Luftballons', ['average', 'all'], cb); },
    function(cb) { createDummyCheck(80, 'My Unstable Site', ['average', 'all'], cb); },
    function(cb) { createDummyCheck(70, 'The lousy site I built for Al', ['low', 'all'], cb); }
  ], callback);
};