How to use the when.join function in when

To help you get started, we’ve selected a few when 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 firebase / firebase-tools / lib / app.js View on Github external
bootstrap: function(argv) {
    var projectRootDir = getProjectRootDir();
    if (projectRootDir !== null) {
      console.log(chalk.red('Initialization Error') + ' - Can\'t create new firebase app ' +
        'inside an existing firebase project');
      process.exit(1);
    }
    _when.join(this.getTemplates(), auth.listFirebases(argv)).done(function(resultSet) {
      var supportedTemplates = resultSet[0],
          res = resultSet[1];

      if (res.firebases.length === 0) {
        console.log(chalk.yellow('You have no apps in your Firebase account'));
        console.log('Sign in to %s and create an app', chalk.cyan('https://firebase.com'));
        console.log('then initialize a directory for hosting');
        process.exit(1);
      }

      // Firebase names always a subset of ^[0-9a-z-]*$ so safe to regex
      var templateList = Object.keys(supportedTemplates).sort();
      var firebasePattern = new RegExp('^(' + res.firebases.join('|') + ')$');
      var templatePattern = new RegExp('^(' + templateList.join('|') + ')$');
      if (!argv.firebase || (typeof(argv.firebase) !== 'string') || !argv.firebase.match(firebasePattern)) {
        res.showFirebases();
github cobyism / ghost-on-heroku / core / server / index.js View on Github external
}).then(function () {
        return when.join(
            // Check for or initialise a dbHash.
            initDbHashAndFirstRun(),
            // Initialize mail
            mailer.init(),
            // Initialize apps
            apps.init()
        );
    }).then(function () {
        var adminHbs = hbs.create(),
github votinginfoproject / Metis / feed-processor / rule / ruleHandler.js View on Github external
done();
            });
          }
          return;
        }

        // Sends the data to the rule to be checked and saved if it is an error
        var promise = RuleHandler.prototype.processDataResults( fetchedData.retrieveRule.ruleDef, fetchedData.entity, fetchedData.dataResults, constraintSet);

        if(promise) {

          if(mainPromise == null) {
            mainPromise = promise;
          }
          else {
            mainPromise = when.join(mainPromise, promise);
          }

          // If too many objects are ing the que to be saved at once pause the stream
          if(++streamObj.saveStackCount >= 1000) {
            logger.info('!Pausing Stream!');
            streamObj.isPaused = true;
            streamObj.stream.pause();
          }

          // Wait for the promise to come back before decrementing the save counter and possibly resuming the stream.
          promise.then(function() {
            if(--streamObj.saveStackCount <= 0 && streamObj.isPaused) {
              logger.info('!Resuming Stream!');
              streamObj.isPaused = false;
              streamObj.stream.resume();
            }
github ohmlabs / ohm / server / ghost / core / server / data / export / index.js View on Github external
exporter = function () {
    var tablesToExport = _.keys(schema);

    return when.join(migration.getDatabaseVersion(), tablesToExport).then(function (results) {
        var version = results[0],
            tables = results[1],
            selectOps = _.map(tables, function (name) {
                if (excludedTables.indexOf(name) < 0) {
                    return knex(name).select();
                }
            });

        return when.all(selectOps).then(function (tableData) {
            var exportData = {
                meta: {
                    exported_on: new Date().getTime(),
                    version: version
                },
                data: {
                    // Filled below
github ohmlabs / ohm / server / ghost / core / server / controllers / admin.js View on Github external
'index': function (req, res) {
        /*jslint unparam:true*/
        function renderIndex() {
            res.render('content', {
                bodyClass: 'manage',
                adminNav: setSelected(adminNavbar, 'content')
            });
        }

        when.join(
            updateCheck(res),
            when(renderIndex())
            // an error here should just get logged
        ).otherwise(errors.logError);
    },
    'content': function (req, res) {
github gruntjs / grunt-contrib / Gruntfile.js View on Github external
// write combined readme for all contrib repos
    var writeReadme = function (packages) {
      var tmpl = grunt.file.read('docs/overview.tmpl');
      var readme = grunt.template.process(tmpl, {data:{plugins:packages}});
      grunt.file.write('docs/overview.md', readme);
    };

    // read all contrib author files
    var authors = when.all(deps.map(authorFile));

    // read all contrib package.json files
    var packages = when.all(deps.map(packageJSON));

    // write author/readme and flag completed
    when.join(authors, packages).then(function (results) {
      writeAuthors(results[0]);
      writeReadme(results[1]);
      done();
    })

  });
github cambecc / earth / server / aws.js View on Github external
Bucket: bucket,
        Key: key,
        ContentType: tool.contentType(path),
        CacheControl: cacheControl(key),
        StorageClass: "REDUCED_REDUNDANCY",  // cheaper
        Metadata: metadata || {}
    };

    if (tool.isCompressionRequired(options.ContentType)) {
        options.ContentEncoding = "gzip";
        path = tool.compress(fs.createReadStream(path));
    }

    var md5 = when(path).then(function(path) { return tool.hash(fs.createReadStream(path)); });

    return when.join(existing, path, md5).spread(function(existing, path, md5) {

        if (existing.statusCode !== 404 &&
                existing.ContentLength * 1 === fs.statSync(path).size &&
                existing.ETag.replace(/"/g, "") === md5.toString("hex") &&
                existing.ContentType === options.ContentType &&
                existing.CacheControl === options.CacheControl) {
            return {unchanged: existing};
        }
        if (!predicate(existing)) {  // predicate must be true to perform upload
            return {unchanged: existing};
        }

        options.ContentMD5 = md5.toString("base64");
        options.Body = fs.createReadStream(path);
        return putObject(options, md5.toString("hex"));
github cujojs / cola / lib / Transaction.js View on Github external
commit: function(datasource) {
			var result = this.runTransaction(datasource);
			return when.all([when.join(result[0], result[1].diff).spread(function(data, diff) {
				return when(datasource.update(diff(data))).yield(data);
			}), datasource]);
		}
	};
github votinginfoproject / Metis / feed-processor / rule / impl / nonExistentLinkRule.js View on Github external
if(!doc._doc[constraintSet.fields[0]])
      return;

    var newProm;
    if(_.isString(doc._doc[constraintSet.fields[0]])) {
      newProm = checkSingle(doc._doc, constraintSet, ruleDefinition, feedId);
    }
    else {
      if(doc._doc[constraintSet.fields[0]].length)
        newProm = checkArray(doc._doc, constraintSet, ruleDefinition, feedId);
    }

    if(newProm) {
      ++totalErrors;
      promise = promise ? when.join(promise, newProm) : newProm;
    }

  });
github cubejs / cluster2 / lib / cache.js View on Github external
function(usr){

				logger.debug('[cache] usr ready, and using namespace:%s & options:%j', namespace, actualOptions);
				return when.join(usr, usr.get('', namespace, function(){

					return actualOptions;
				}));
			},