How to use the async.forEachSeries 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 CleverStack / node-seed / bin / seedModels.js View on Github external
// Setup ODM
if ( config.odm && config.odm.enabled ) {
  mongoose.connect(config.mongoose.uri);
}

// Run our model injection service
modelInjector( models );

var seedData = require('./../schema/seedData.json');

var assocMap = {};
Object.keys(seedData).forEach(function( modelName ) {
    assocMap[modelName] = [];
});

async.forEachSeries(
    Object.keys(seedData),
    function forEachModelType( modelName, cb ) {
        var ModelType = models.ORM[modelName]
            , Models = seedData[modelName];

        async.forEachSeries(
            Models,
            function forEachModel( data, modelCb ) {
                var assocs = data.associations;
                delete data.associations;

                ModelType.create(data).success(function( model ) {
                    data.associations = assocs;

                    console.log('Created ' + modelName);
                    assocMap[modelName].push(model);
github NetEase / pomelo / lib / common / manager / appManager.js View on Github external
return;
  }

  var cmethods=[] ,dmethods=[], cnames=[], dnames=[];
  for(var key in conditions) {
    if(typeof key !== 'string' || typeof conditions[key] !== 'function') {
      logger.error('transaction conditions parameter is error format, condition name: %s, condition function: %j.', key, conditions[key]);
      return;
    }
    cnames.push(key);
    cmethods.push(conditions[key]);
  }

  var i = 0;
  // execute conditions
  async.forEachSeries(cmethods, function(method, cb) {
    method(cb);
    transactionLogger.info('[%s]:[%s] condition is executed.', name, cnames[i]);
    i++;
  }, function(err) {
    if(err) {
      process.nextTick(function() {
        transactionLogger.error('[%s]:[%s] condition is executed with err: %j.', name, cnames[--i], err.stack);
        var log = {
          name: name,
          method: cnames[i],
          time: Date.now(),
          type: 'condition',
          description: err.stack
        };
        transactionErrorLogger.error(JSON.stringify(log));
      });
github Level / leveldown / test / benchmarks / index.js View on Github external
console.log()
            callback.apply(null, arguments)
          }
      )
    }

  , focusKey = Object.keys(tests).filter(function (k) { return (/\=>/).test(k) })

if (focusKey.length) {
  var focusTest = tests[focusKey[0]]
  tests = {}
  tests[focusKey[0]] = focusTest
}

require('colors')
async.forEachSeries(Object.keys(tests), runTest)
github paulstraw / Grind / lib / grind.js View on Github external
function hint() {
	var hint = require('jshint').JSHINT,
		hintOpts = config.hint === true ? null : config.hint;

	async.forEachSeries(files, function(file, callback) {
		var hinted = hint(file.content, hintOpts);

		if (!hinted) {
			if (hint.errors[hint.errors.length - 1] === null) {
				console.error(clc.red('JSHint encountered a fatal error in ' + file.path));
				process.exit(1);
			}

			console.warn(clc.yellow('JSHint found ' + hint.errors.length + ' problem(s) with ' + file.path + '.'));

			async.forEachSeries(hint.errors, function(error, cb) {
				console.warn('	' + error.line + '.' + error.character + ': ' + error.reason);
				cb();
			}, function() {
				callback();
			});
github spmjs / spm / lib / plugins / loadSourceConfig.js View on Github external
if (help.isLocalPath(source)) {
    configPath = path.join(source, 'config.json');
    if (fsExt.existsSync(configPath)) {
      config = eval('(' + fs.readFileSync(configPath) + ')');
      mergeConfig(project, config);
    } else {
      console.log(errMsg);
    }
    callback();
  } else {
    var sourceUrls = [source];
    var root = project.root;
    if (root && root !== '#') {
      sourceUrls.unshift(source + '/' + root);
    }
    async.forEachSeries(sourceUrls, function(sourceUrl, callback) {
      mergeSourceConfig(sourceUrl, callback);
    }, function(err) {
      callback();
    });
  }
};
github smartscenes / sstk / ssc / clean-segment-annotations.js View on Github external
function processIds(ids, outdir, doneCallback) {
  shell.mkdir('-p', outdir);
  var aggregatedStats = {};
  async.forEachSeries(ids, function (id, callback) {
    var mInfo = assetsDb.getAssetInfo(argv.source + '.' + id);
    var loadInfo = assetManager.getLoadModelInfo(argv.source, id, mInfo);
    assetManager.getModelInstanceFromLoadModelInfo(loadInfo, function (mInst) {
      segments.init(mInst);
      mInst.model.info.annId = loadInfo.annId;
      segments.loadSegments(function (err, res) {
        if (!err) {
          var filename = outdir + '/' + id + '.anns.json';
          cleanAnnotations(loadInfo, filename, segments, aggregatedStats);
        }
        setTimeout(function () {
          callback();
        }, 0);
      });
    });
  }, function (err, results) {
github jsreport / jsreport / lib / util / listenerCollection.js View on Github external
}
            catch (e) {
                currentArgs.unshift(e);
                applyHook(l, "_postFail", currentArgs);
                return q.reject(e);
            }

        }).then(function() {
            return results;
        });
    }

    //remove callback
    args.pop();

    return async.forEachSeries(this._listeners, function(l, next) {
        var currentArgs = args.slice(0);
        currentArgs.push(next);
        l.fn.apply(l.context, currentArgs);

    }, arguments[arguments.length - 1]);
};
github joyent / smartos-live / src / img / lib / imgadm.js View on Github external
missing.push(u);
                } else {
                    imagesInfo.push(iiFromUuid[u]);
                }
            });
            if (missing.length) {
                callback(new errors.UsageError(
                    'no install image with the given UUID(s): '
                    + missing.join(', ')));
                return;
            }
        } else {
            imagesInfo = ii;
        }

        async.forEachSeries(
            imagesInfo,
            updateImage,
            function (err) {
                if (err) {
                    callback(err);
                } else if (updateErrs.length === 1) {
                    callback(updateErrs[0]);
                } else if (updateErrs.length > 1) {
                    callback(new errors.MultiError(updateErrs));
                } else {
                    callback();
                }
            });
    });
github peteclark82 / cuke-tree / lib / assets / clientAssetManager.js View on Github external
function forEachAsset(assets, callback, finishedCallback) {
	async.forEachSeries(Object.keys(assets), function(extensionName, nextGroup) {
		var extensionAssets = assets[extensionName];
		async.forEachSeries(Object.keys(extensionAssets), function(groupName, nextAssetType) {
			var group = extensionAssets[groupName];
			async.forEachSeries(group, function(asset, nextAsset) {
				callback({
					extensionAssets : extensionAssets,
					extensionName : extensionName,
					group : group,
					groupName : groupName,
					asset : asset
				}, nextAsset);
			}, function(err) { nextAssetType(err); });
		}, function(err) { nextGroup(err); });
	}, function(err) { finishedCallback(err); });
}