How to use the bluebird.join function in bluebird

To help you get started, we’ve selected a few bluebird 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 LiskHQ / lisk-sdk / test / unit / sql / rounds.js View on Github external
it('should calculate rewards for round 1 correctly - all should be the same (native, rounds_rewards, delegates)', function () {
			var round = 1;
			var expectedRewards;

			return Promise.join(getBlocks(round), getRoundRewards(round), getDelegates(), function (blocks, rewards, delegates) {
				// Get expected rewards for round (native)
				expectedRewards = getExpectedRoundRewards(blocks);
				// Rewards from database table rounds_rewards should match native rewards
				expect(rewards).to.deep.equal(expectedRewards);

				expect(delegates_state[outsider_pk].blocks_missed_cnt).to.equal(1);
				return Promise.reduce(delegates, function (delegates, d) {
					if (d.fees > 0 || d.rewards > 0) {
						// Normalize database data
						delegates[d.pk] = {
							pk: d.pk,
							fees: Number(d.fees),
							rewards: Number(d.rewards)
						}
					}
					return delegates;
github fullcube / loopback-component-access-groups / lib / utils.js View on Github external
cb(null, false)
          })
          return cb.promise
        }

        this.isGroupMemberWithRole(modelClass, modelId, userId, roleName)
          .then(res => cb(null, res))
          .catch(cb)

        return cb.promise
      }

      /**
       * More complex application that also covers static methods. (EXPERIMENTAL)
       */
      Promise.join(this.getCurrentGroupId(context), this.getTargetGroupId(context),
        (currentGroupId, targetGroupId) => {
          if (!currentGroupId) {
            // TODO: Use promise cancellation to abort the chain early.
            // Causes the access check to be bypassed (see below).
            return [ false ]
          }

          scope.currentGroupId = currentGroupId
          scope.targetGroupId = targetGroupId
          const actions = [ ]
          const conditions = { userId, role: roleName }

          conditions[this.options.foreignKey] = currentGroupId
          actions.push(GroupAccess.count(conditions))

          // If this is an attempt to save the item into a new group, check the user has access to the target group.
github arabold / serverless-sentry-plugin / src / index.js View on Github external
_resolveGitRefs(gitRev) {
		return BbPromise.join(
			gitRev.origin().then(str => str.match(/[:/]([^/]+\/[^/]+?)(?:\.git)?$/i)[1]).catch(_.noop),
			gitRev.long()
		)
		.spread((repository, commit) => {
			_.forEach(_.get(this.sentry, "release.refs", []), ref => {
				if (ref && ref.repository === "git") {
					ref.repository = repository;
				}
				if (ref && ref.commit === "git") {
					ref.commit = commit;
				}
				if (ref && ref.previousCommit === "git") {
					delete ref.previousCommit; // not available via git
				}
			});
		});
github Versent / cfn-check / bin / cfn-check.js View on Github external
parse(fs.readFileSync(program.args[0], 'utf8')).then(function (template) {
    return Promise.join(
      check.references.areValid(template),
      check.resources.areValid(template),
      function (referencesErrors, resourcesErrors) {
        var errors = _.concat(referencesErrors, resourcesErrors);
        if (errors.length > 0) {
          console.log(errors.join('\n'));
          process.exit(1);
        } else {
          console.log(JSON.stringify(template, null, spacer));
          process.exit(0);
        }
      });
  })
  .catch(function (error) {
github bunkerchat / bunker / server / services / fightService.js View on Github external
function buildFightResultsResponse(fight, rounds) {
	return Promise.join(
		User.findOne({ _id: fight.challenger.id.toObjectId() }),
		User.findOne({ _id: fight.opponent.id.toObjectId() })
	).spread(function(challenger, opponent) {
		var opponentNick = opponent.nick;
		var challengerNick = challenger.nick;
		var roundData = _.map(rounds, function(round) {
			return getRoundPlayData(round, challenger, opponent);
		});

		var responseString = [];
		responseString.push("Fight between @" + challengerNick + " and @" + opponentNick + " has begun!");
		_.each(roundData, function(data) {
			responseString.push(data.message);
		});

		var fightResultData = getFightResultData(challenger, opponent, rounds);
github Emapic / emapic / routes / main.js View on Github external
app.get('/dashboard', requireRole(null), function(req, res){
        Promise.join(req.user.getAnsweredSurveysAndCount({
                limit: 5
            }),
            req.user.getSurveys({
                where: {
                    active: {
                        [Op.ne]: null
                    }
                }
            }),
            function(answered, created) {
                res.render('dashboard', {
                    answered: answered.rows,
                    ans_count: answered.count,
                    cre_count: created.length,
                    layout: 'layouts/main'
                });
github trainline / environment-manager / server / modules / environment-state / getServiceHealth.js View on Github external
function getCurrentState(filters) {
  let fullyQualifiedServiceNames = fullyQualifiedServiceNamesFor(filters);
  let serviceHealthP = getHealth(fullyQualifiedServiceNames);
  let instancesP = serviceHealthP
    .then(serviceHealth => instancesRequestFor(getAccountNameForEnvironment, serviceHealth))
    .then(getInstances)
    .then(flatMap(instancesOf))
    .then(reduce(assign, {}));

  return Promise.join(serviceHealthP, instancesP, currentState);
}
github KoryNunn / righto-v-promise / createUsers / promiseDb.js View on Github external
return db.Users.create({
            name: 'bob smith',
            addressId: address.id,
            profileId: profile.id
        });
    }

    function createUser2Data(address, profile){
        return db.Users.create({
            name: 'john down',
            addressId: address.id,
            profileId: profile.id
        });
    }

    var user1 = Promise.join(address1, profile1, createUser1Data);

    var user2 = Promise.join(address2, profile2, createUser2Data);

    Promise.all([user1, user2])
    .then(function(result){
        callback(null, result);
    })
    .catch(callback);
};
github ZZROTDesign / alpine-ghost / ghost / Gruntfile.js View on Github external
grunt.registerTask('buildAboutPage', 'Compile assets for the About Ghost page', function () {
            var done = this.async(),
                templatePath = 'core/client/app/templates/-contributors.hbs',
                imagePath = 'core/client/public/assets/img/contributors/',
                timeSpan = moment().subtract(90, 'days').format('YYYY-MM-DD'),
                oauthKey = process.env.GITHUB_OAUTH_KEY;

            if (fs.existsSync(templatePath) && !grunt.option('force')) {
                grunt.log.writeln('Contributors template already exists.');
                grunt.log.writeln(chalk.bold('Skipped'));
                return done();
            }

            grunt.verbose.writeln('Downloading release and contributor information from GitHub');

            return Promise.join(
                Promise.promisify(fs.mkdirs)(imagePath),
                getTopContribs({
                    user: 'tryghost',
                    repo: 'ghost',
                    oauthKey: oauthKey,
                    sinceDate: timeSpan,
                    count: 18,
                    retry: true
                })
            ).then(function (results) {
                var contributors = results[1],
                    contributorTemplate = '<article>\n    <a title="<%name%>" href="<%githubUrl%>">\n' +
                        '        <img src="{{gh-path">" alt="&lt;%name%&gt;" /&gt;\n' +
                        '    </a>\n</article>',

                    downloadImagePromise = function (url, name) {