How to use the async.each 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 Rcomian / bunyan-rotating-file-stream / lib / datestampedfileops.js View on Github external
function findUnusedFile(nonce, next) {
        var filepath = internalGetStreamFilepath(false, nonce);
        var filepathgz = internalGetStreamFilepath(true, nonce);

        async.each([
            filepath,
            filepathgz
        ], function (potentialpath, pathresult) {
            fs.stat(potentialpath, function (err, stats) {
                if (err && err.code === 'ENOENT') {
                    // File doesn't already exist, this is good
                    pathresult();
                } else if (err) {
                    // Something else failed
                    pathresult(err);
                } else {
                    // Path existed, use something else
                    pathresult('inuse');
                }
            })
        }, function (err) {
github tarlepp / Taskboard / api / controllers / StoryController.js View on Github external
function processCommentCopy(comments, destinationId, parentCommentId, next) {
            async.each(
                comments,

                /**
                 * Iterator function to create new comment and process possible sibling comments.
                 *
                 * @param   {sails.model.comment}   comment     Single comment object
                 * @param   {Function}              callback    Callback function which
                 */
                function(comment, callback) {
                    delete comment.id;

                    // Change necessary comment data
                    comment.objectId = destinationId;
                    comment.commentId = parentCommentId;

                    // Create new comment
github JedWatson / sydjs-site / updates / old / 0.2.2-add-meetup-dates.js View on Github external
keystone.list('Meetup').model.find().exec(function(err, meetups) {
		async.each(meetups, function(meetup, doneMeetup) {
			meetup.set({
				state: 'draft', // Date is in a corrupted state, throws validation errors unless we first set a default
				publishedDate: moment(meetup.date).subtract('days', 7).toDate() // Set 7 days before actual meetup date
			}).save(function(err) {
				return doneMeetup();
			});
		}, function(err) {
			return done();
		});
	});
github ericgj / metalsmith-branch / test / index.js View on Github external
function remover(files,ms,done){
      function remove(name,done){
        delete files[name];
        done();
      }
      debug('remover');
      each(Object.keys(files), remove, done);
    }
github softwerkskammer / Agora / softwerkskammer / changeGroupname.js View on Github external
mailsPersistence.listByField({group: oldId}, {}, function (err4, results1) {
            async.each(results1,
              function (each, callback) {
                each.group = newId;
                mailsPersistence.save(each, callback);
              },
              function (err5) {
                handle(err5);
                Git.mv(oldId, newId, 'Group rename: ' + oldId + ' -> ' + newId, 'Nicole ', function (err6) {
                  handle(err6);
                  closeDBsAndExit();
                });
              });
          });
        });
github ethereum / remix / remix-lib / src / execution / txListener.js View on Github external
_resolve (transactions, callback) {
    async.each(transactions, (tx, cb) => {
      this._api.resolveReceipt(tx, (error, receipt) => {
        if (error) return cb(error)
        this._resolveTx(tx, receipt, (error, resolvedData) => {
          if (error) cb(error)
          if (resolvedData) {
            this.event.trigger('txResolved', [tx, receipt, resolvedData])
          }
          this.event.trigger('newTransaction', [tx, receipt])
          cb()
        })
      })
    }, () => {
      callback()
    })
  }
github cbou / markdox / lib / markdox.js View on Github external
options = options || {};

  options = u.defaults(options, {
    output: false
    , encoding: 'utf-8'
    , formatter: formatter
  });

  if (!util.isArray(files)) {
    files = [files];
  }

  var docfiles = {};
  var root = process.cwd()

  async.each(files, function(file, callback){

    exports.parse(file, options, function(err, doc){
      var filename = path.relative(process.cwd(), file);
      var docfile = {
        filename: filename,
        javadoc: doc
      };

      var formatedDocfile = options.formatter(docfile);
      docfiles[file] = formatedDocfile;
      callback(err);
    });

  }, function (err) {
    exports.generate(files.map(function (file) {
      return docfiles[file];
github mtgjson / mtgjson3 / web / index.js View on Github external
fs.readdir(dir, function(err, list) {
        if (err) return(callback(err));

        if (list.length == 0) return(setImmediate(callback, null, results));

        async.each(
            list,
            function(file, cb) {
                file = path.resolve(dir, file);

                fs.stat(file, function(err, stat) {
                    if (err) return(callback(err));

                    if (stat && stat.isDirectory())
                        walk(file, function(err, res) {
                            results = results.concat(res);
                            cb();
                        });
                    else {
                        results.push(file);
                        cb();
                    }
github NodeBB / NodeBB / src / plugins / hooks.js View on Github external
function fireStaticHook(hook, hookList, params, callback) {
		if (!Array.isArray(hookList) || !hookList.length) {
			return callback();
		}
		async.each(hookList, function (hookObj, next) {
			if (typeof hookObj.method === 'function') {
				let timedOut = false;
				const timeoutId = setTimeout(function () {
					winston.warn('[plugins] Callback timed out, hook \'' + hook + '\' in plugin \'' + hookObj.id + '\'');
					timedOut = true;
					next();
				}, 5000);

				const onError = (err) => {
					winston.error('[plugins] Error executing \'' + hook + '\' in plugin \'' + hookObj.id + '\'');
					winston.error(err);
					clearTimeout(timeoutId);
					next();
				};
				const callback = (...args) => {
					clearTimeout(timeoutId);
github ngageoint / mage-server / routes / esriFeatures.js View on Github external
filters = [];
      geometries.forEach(function(geometry) {
        filters.push({
          geometry: geometry
        });
      });
    }

    var respond = function(features) {
      var response = esri.transform(features, req.parameters.fields);
      res.json(response);
    }

    if (filters) {
      allFeatures = [];
      async.each(
        filters, 
        function(filter, done) {
          Feature.getFeatures(req.layer, filter, function (features) {
            if (features) {
              allFeatures = allFeatures.concat(features);
            }

            done();
          });
        },
        function(err) {
          respond(allFeatures);
        }
      );
    } else {
      var filter = {};