How to use the es6-promise.Promise.all function in es6-promise

To help you get started, we’ve selected a few es6-promise 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 buzinas / tslint-eslint-rules / src / readme / index.ts View on Github external
function updateRuleFiles(cb: Function) {
  const ruleDir = 'src/rules/';
  const allFiles = fs.readdirSync(ruleDir).filter(
    file => fs.lstatSync(path.join(ruleDir, file)).isFile()
  );
  const ruleNames = allFiles
    .filter(name => /\.ts$/.test(name))
    .map(name => name.substr(0, name.length - 7));
  const allPromises: Promise[] = [];
  ruleNames.forEach((name) => {
    allPromises.push(updateRuleFile(name, ruleTSMap[name]));
  });
  // Only do the callback when all the promises have been resolved.
  Promise.all(allPromises).then(() => {
    console.log('[DONE] processing rule files ...');
    cb();
  });
}
github snyk / snyk / lib / policy / index.js View on Github external
function mergePolicies(policyDirs, options) {
  var ignoreTarget = options['trust-policies'] ? 'ignore' : 'suggest';

  return Promise.all(policyDirs.map(function (dir) {
    return load(dir, options);
  })).then(function (policies) {
    // firstly extend the paths in the ignore and patch
    var rootPolicy = policies[0];
    var others = policies.slice(1);

    return Promise.all(others.map(function (policy) {
      var filename = path.dirname(policy.__filename) + '/package.json';

      return tryRequire(filename).then(function (pkg) {
        var full = pkg.name + '@' + pkg.version;

        mergePath('ignore', ignoreTarget, full, rootPolicy, policy);
        mergePath('patch', 'patch', full, rootPolicy, policy);
      });
    })).then(function () {
github IBM / cognitive-social-crm / server / src / dao / CloudantDAO.ts View on Github external
this.dbName = dbName;
              // Now create any design docs that might be defined
              const designCreatePromises = this.buildDesignCreatePromiseArray(dbName, dbConfig, createHash);
              Promise.all(designCreatePromises).then((designResult) => {
                const dbResult: any = { dbName, exist: true, design: [] };
                dbResult.design = designResult;
                resolve(dbResult);
              });
            }
          });
        } else {
          this.LOGGER.info('Database ' + dbName + ' already exist, creating designs');
          // Now create any design docs that might be defined
          const designCreatePromises = this.buildDesignCreatePromiseArray(dbName, dbConfig, createHash);

          Promise.all(designCreatePromises).then((designResult) => {
            const dbResult: any = { dbName, exist: true, design: [] };
            dbResult.design = designResult;
            resolve(dbResult);
          });
        }
      } catch (err) {
        this.LOGGER.info('Error in creating cloudant database : ' + err);
        reject(err);
      }
    });
  }
github manifoldco / torus-cli / cli / lib / user / invite.js View on Github external
};

    if (!data.org) {
      return reject(new Error('--org is required'));
    }

    var errors = validator(data);
    if (errors.length > 0) {
      return reject(errors[0]);
    }


    var user;
    var org;
    var team;
    return Promise.all([
      ctx.api.users.profile({}, { username: data.username }),
      ctx.api.orgs.get({ name: data.org })
    ])
    .then(function (results) {
      user = _.get(results, '[0]', null);
      org = _.get(results, '[1][0]', null);

      if (!user) {
        throw new Error('user not found: ' + data.username);
      }

      if (!org) {
        throw new Error('org not found: ' + data.org);
      }
    })
    .then(function () {
github ChtiJS / chtijs.francejs.org / gulpplugins / ghmembers.js View on Github external
file[options.prop].members.map(function(member) {
          return Promise.all([
            ghrequest(member.url),
            new Promise(function(resolve) {
              var bioPath = path.join(
                __dirname,
                '..',
                'documents',
                'bios',
                'fr',
                member.login + '.md'
              );

              fs.readFile(bioPath, function(err, data) {
                if (err) {
                  return resolve();
                }
                resolve(data);
github 5thWall / mustache-render / tasks / mustache_render.js View on Github external
return new Promise(function renderPromise(resolve, reject) {
      Promise.all([this._getData(data), this._getBody(template)]).

      then(function gotDataAndBody(results) {
        var dataObj = results[0], body = results[1];

        grunt.log.writeln("Output " + dest + ":");
        grunt.file.write(dest, mustache.render(body, dataObj,
                                               this._getPartial.bind(this)));
        grunt.log.ok(
          (
            typeof dataObj === 'object' ?
            (Object.keys(dataObj).length + "-key object").green :
            "non-object data".yellow
          ) +
          " into " + template.cyan +
          " from " + (typeof data === 'string' ? data : "JavaScript code").cyan
        );
github intermine / im-tables / src / views / lookup-value-controls.js View on Github external
provideSuggestions() {
    this.removeTypeAheads();
    const suggestingValue = this.suggestValue();
    const suggestingExtra = this.suggestExtra();
    return Promise.all([suggestingExtra, suggestingValue]);
  }
github apendua / phantom-as-promise / promesify.js View on Github external
constructor.prototype[method] = function () {
      var args = Array.prototype.slice.call(arguments);
      return (new constructor(this._operand, Promise.all([ this._operand, this._promise ]))).then(function (all) {
        var original = all[0][method];
        var callback = args[args.length-1];
        //---------------------------------------------
        return new Promise(function (resolve, reject) {
          if (typeof callback === 'function') {
            args[args.length-1] = function () {
              resolve(callback.apply(this, arguments));
            }
          } else {
            args.push(either(reject).or(resolve));
          }
          original.apply(all[0], args);
        });
      });
    };
  });
github tettusud / merge-jsons-webpack-plugin / index.ts View on Github external
} else if (groupBy) {
                if (groupBy.length == 0) {
                    compilation.errors.push('MergeJsonWebpackPlugin: \"groupBy\" must be non empty object');
                }
                let globOptions = this.options.globOptions || {};
                let groupByPromises = groupBy.map((globs: any) => {
                    return new Promise((resolve, reject) => {
                        let pattern = globs.pattern;
                        let outputPath = globs.fileName;
                        this._glob(pattern, globOptions).then((files) => {
                            this.processFiles(files, outputPath, resolve, reject);
                        });
                    });
                });
                //wait for all groupBy array operations to finish
                Promise.all(groupByPromises)
                    .then((opsResponse) => {
                        //res contains Response of all groupBy operations
                        opsResponse.forEach((res: Response) => {
                            this.addAssets(compilation, res);
                        });
                        done();
                    })
                    .catch((err) => {
                        this.handleErrors(compilation, err, done);
                    });
            }
            this.logger.debug('MergeJsonsWebpackPlugin emit completed...');
        }