How to use the async.map 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 awslabs / lambda-refarch-mapreduce / src / nodejs / reducerCoordinator.js View on Github external
bucket: bucket,
                                keys: _get_keys(batch),
                                jobBucket: bucket,
                                jobId: jobId,
                                nReducers: nReducers, 
                                stepId: stepId, 
                                reducerId: i 
                            })
                        };
                    lambdaBatchParams.push(params);
                }

                console.log("LBR", lambdaBatchParams);

                /// Stream the files from S3 & Reduce
                async.map(lambdaBatchParams, invokeLambda, function (err, rResults){
                    if (err){
                        console.error(err);
                        callback(null, 'Reducer invocation error');
                        return;
                    }

                    var fname = jobId + "/reducerstate." + stepId;
                    writeReducerState(nReducers, nS3, bucket, fname, function(err, data){
                        callback(null, 'Invoked Reducer Step');
                    });
                });


          });
        }else{
github silverwind / droppy / server / resources.js View on Github external
fs.readFile(path.join(paths.mod, "/node_modules/codemirror/mode/meta.js"), (err, js) => {
    if (err) return callback(err);

    // Extract modes from CodeMirror
    const sandbox = {CodeMirror : {}};
    vm.runInNewContext(js, sandbox);
    sandbox.CodeMirror.modeInfo.forEach(entry => {
      if (entry.mode !== "null") modes[entry.mode] = null;
    });

    async.map(Object.keys(modes), (mode, cb) => {
      fs.readFile(path.join(modesPath, mode, mode + ".js"), (err, data) => {
        cb(err, Buffer.from(minifyJS(String(data))));
      });
    }, (err, result) => {
      Object.keys(modes).forEach((mode, i) => {
        modes[mode] = result[i];
      });
      callback(err, modes);
    });
  });
}
github NodeBB / NodeBB / src / posts / uploads.js View on Github external
Posts.uploads.getUsage = function (filePaths, callback) {
		// Given an array of file names, determines which pids they are used in
		if (!Array.isArray(filePaths)) {
			filePaths = [filePaths];
		}

		const keys = filePaths.map(fileObj => 'upload:' + md5(fileObj.name.replace('-resized', '')) + ':pids');
		async.map(keys, function (key, next) {
			db.getSortedSetRange(key, 0, -1, next);
		}, callback);
	};
github BlackPearSw / fhirball / lib / Router / index.js View on Github external
function parseConformance(callback) {
        async.map(options.conformance.rest, parseRest, function (err) {
            if (err) return callback(err);
        });
        callback();
    }
github node-tastypie / tastypie / lib / fields / related.js View on Github external
this.parent('dehydrate', obj, function( err, value ){
      if( err ){
        return cb && cb( err, null );
      }

      if( that.options.full ){
        return cb( err, value );
      } else if( that.options.minimal ){
        async.map(
          value,
          that.to_minimal.bind( that ),
          cb
        );
      } else{
        return cb( err, value && value.map(that.instance.to_uri.bind( that.instance ) ) );
      }
    });
  }
github bitpay / bitcore / packages / bitcore-wallet-service / src / lib / pushnotificationsservice.ts View on Github external
(contents, next) => {
              async.map(
                recipientsList,
                (recipient: IPreferences, next) => {
                  const content = contents[recipient.language];

                  this.storage.fetchPushNotificationSubs(
                    recipient.copayerId,
                    (err, subs) => {
                      if (err) return next(err);

                      const notifications = _.map(subs, (sub) => {
                        return {
                          to: sub.token,
                          priority: 'high',
                          restricted_package_name: sub.packageName,
                          notification: {
                            title: content.plain.subject,
github scality / backbeat / lib / queuePopulator / IngestionReader.js View on Github external
_readInitState(logger, done) {
        const initPathNodes = IngestionReader.getInitIngestionNodes();

        if (this._shouldProcessInitState === false) {
            return done(null, {
                isStatusComplete: true,
            });
        }

        return async.map(initPathNodes, (pathNode, cb) => {
            const path = `${this.bucketInitPath}/${pathNode}`;
            return this.zkClient.getData(path, (err, data) => {
                if (err) {
                    if (err.name !== 'NO_NODE') {
                        logger.error(
                            'Could not fetch ingestion init state',
                            { method: 'IngestionReader._readInitState',
                              zkPath: path,
                              error: err });
                        return cb(err);
                    }
                    return this.zkClient.mkdirp(path, err => {
                        if (err) {
                            logger.error(
                                'Could not pre-create path in zookeeper',
                                { method: 'IngestionReader._readInitState',
github jeresig / idyll / server / routes / index.js View on Github external
var cleanTask = function(req, res, task) {
    async.map(task.files, function(file, callback) {
        var buffers = [];
        var stream = file.path.indexOf("http") === 0 ?
            request(file.path) :
            fs.createReadStream(file.path);

        stream.on("data", function(buffer) {
            buffers.push(buffer);
        })
        .on("end", function() {
            callback(null, {
                name: file.name,
                type: file.type,
                file: Buffer.concat(buffers).toString("base64"),
                data: file.data
            });
        });
github taoyuan / slu-seed / lib / seed.js View on Github external
function _seed(Model, data, next) {
    if (!Array.isArray(data)) data = [data];
    async.map(data, function (item, callback) {
      debug('Seed %s: %s', Model.modelName, JSON.stringify(item).substr(0, 80));
      Model.upsert(item, callback);
    }, next);
  }
}
github alphagov / spotlight / app / support / stagecraft_stub / stagecraft_stub_controller.js View on Github external
function loadRelated(basePath, callback) {
  async.map([
    basePath + '/departments.json',
    basePath + '/business-models.json',
    basePath + '/customer-types.json',
    basePath + '/agencies.json'
  ], fs.readFile,
  function(err, content) {
    var json = content.map(JSON.parse.bind(JSON)),
        related = { };

    related.departments = json[0];
    related.businessModels = json[1];
    related.customerTypes = json[2];
    related.agencies = json[3];

    callback(null, related);
  });