How to use the async.eachLimit 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 bitpay / insight-api / app / controllers / addresses.js View on Github external
txs.sort(function(a, b) {
      var b = (b.firstSeenTs || b.ts)+ b.txid;
      var a = (a.firstSeenTs || a.ts)+ a.txid;
      if (a > b) return -1;
      if (a < b) return 1;
      return 0;
    });
    txs = txs.slice(from, to);

    var txIndex = {};
    _.each(txs, function(tx) {
      txIndex[tx.txid] = tx;
    });

    async.eachLimit(txs, RPC_CONCURRENCY, function(tx2, callback) {
      tDb.fromIdWithInfo(tx2.txid, function(err, tx) {
        if (err) {
          console.log(err);
          return common.handleErrors(err, res);
        }
        if (tx && tx.info) {

          if (tx2.firstSeenTs)
            tx.info.firstSeenTs = tx2.firstSeenTs;

          txIndex[tx.txid].info = tx.info;
        } else {
          // TX no longer available
          txIndex[tx2.txid].info = {
            txid: tx2.txid,
            possibleDoubleSpend: true,
github jeresig / pharos-images / logic / artworks.js View on Github external
const title = artwork.getTitle(req);

                    // Sort the similar artworks by score
                    artwork.similarArtworks = artwork.similarArtworks
                        .sort((a, b) => b.score - a.score);

                    if (!compare) {
                        return res.render("Artwork", {
                            title,
                            compare: false,
                            artworks: [artwork],
                            similar: artwork.similarArtworks,
                        });
                    }

                    async.eachLimit(artwork.similarArtworks, 4,
                        (similar, callback) => {
                            similar.artwork.loadImages(false, callback);
                        }, () => {
                            res.render("Artwork", {
                                title,
                                compare: true,
                                noIndex: true,
                                similar: [],
                                artworks: [artwork]
                                    .concat(artwork.similarArtworks
                                        .map((similar) => similar.artwork)),
                            });
                        });
                });
            });
github akhoury / nodebb-plugin-ubbmigrator / ubbmigrator.js View on Github external
setTopics: function(next) {
			var count = 0;
			var startTime = new Date().getTime();

			async.eachLimit(m.mem._otids, m.nbb.config.topicsBatchSize, function(_otid, done) {
				count++;

				var topicData = storage.getItem('t.' + _otid);

				var topic = topicData.normalized;
				var migratedTopic = topicData.migrated;
				var skippedTopic = topicData.skipped;

				if (migratedTopic || skippedTopic) {
					logger.info('[c:' + count + '] topic: ' + _otid + ' already processed, destiny: ' + (migratedTopic ? 'migrated' : 'skipped'));
					// todo hack!
					// process.nextTick is also crashing
					setTimeout(function(){
						done();
					}, 1);
				}  else {
github gbif / portal16 / app / views / pages / tools / speciesLookup / speciesLookup.entry.js View on Github external
function lookupNames() {
        async.eachLimit(vm.species, 10, lookupName, function(err) {
            if (err) {
                // TODO inform the user that not everything could be matched
            } else {
                vm.lookupComplete = true;
            }
        });
    }
github EasyERP / EasyERP_open_source / updateCollections / Done / updateEmployeeTransferDepartment.js View on Github external
query.exec(function (error, _res) {
    if (error) {
        return console.dir(error);
    }

    async.eachLimit(_res, 50, function (emp, callback) {
        var objectToSave;
        var transfer = emp.transfer;
        var newTransfer = [];
        var newTr;

        transfer = transfer.forEach(function (tr, i) {
            if (i !== 0) {
                if (tr.department.toString() !== transfer[i - 1].department.toString()) {
                    newTr = JSON.parse(JSON.stringify(transfer[i - 1]));

                    newTr.status = 'transfer';
                    newTr.manager = ObjectId(newTr.manager);
                    newTr.jobPosition = ObjectId(newTr.jobPosition);
                    newTr.date = moment(tr.date);
                    newTr.date = newTr.date.subtract(1, 'days');
                    newTransfer.push(newTr);
github longshoreman / longshoreman / src / router.js View on Github external
async.each(apps, function(app, fn) {
    async.eachLimit(INSTANCES[app], 5, function(host, fn) {
      healthCheckHost(app, host, fn);
    }, fn);
  }, fn);
}
github AugurProject / augur / packages / augur.js / src / reporting / claim-reporting-fees-nonforked-markets.js View on Github external
if (p.nonforkedMarkets[i].isFinalized) {
        redeemableContracts.push({
          address: p.nonforkedMarkets[i].initialReporter,
          type: contractTypes.INITIAL_REPORTER,
        });
      }
    } else {
      redeemableContracts.push({
        address: p.nonforkedMarkets[i].initialReporter,
        type: contractTypes.INITIAL_REPORTER,
      });
    }
  }

  var limit = p.estimateGas ? PARALLEL_LIMIT : 1;
  async.eachLimit(redeemableContracts, limit, function (contract, nextContract) {
    switch (contract.type) {
      case contractTypes.DISPUTE_WINDOW:
        api().DisputeWindow.redeem(assign({}, payload, {
          _sender: p.redeemer,
          tx: {
            to: contract.address,
            estimateGas: p.estimateGas,
          },
          onSent: function () {
            if (!p.estimateGas) {
              nextContract();
            }
          },
          onSuccess: function (result) {
            if (p.estimateGas) {
              result = new BigNumber(result, 16);
github NodeBB / NodeBB / src / upgrade.js View on Github external
Groups.list({showSystemGroups: true}, function(err, groups) {
							if (err) {
								return next(err);
							}

							async.eachLimit(cids, 50, function(cid, next) {
								upgradePrivileges(cid, groups, next);
							}, next);
						});
					}
github serverless / serverless / lib / actions / CodeEventDeployLambda.js View on Github external
return new BbPromise(function (resolve, reject) {

        let deployedEvents = [];

        async.eachLimit(evt.function.events, 5, function (event, cb) {

          let params = {
            FunctionName: _this.Lambda.sGetLambdaName(_this.S.data.project.get('name'), evt.function.module, evt.function.name),
            EventSourceArn: event.eventSourceArn,
            StartingPosition: event.startingPosition,
            BatchSize: event.batchSize,
            Enabled: event.enabled
          };

          return _this.Lambda.createEventSourceMappingPromised(params)
            .then(function (data) {

              SUtils.sDebug(`Created event source ${event.eventSourceArn} for lambda ${evt.function.name}`);

              params.UUID = data.UUID;
              deployedEvents.push(params)