How to use the when.all 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 jstty / hyper.io / legacy / manager.service.js View on Github external
} catch (err) {
        service.logger.error('Post Start Init Service Error:', err);
        return when.reject(err);
      }
    }

    //
    result = service.resources.postStartInit();
    service._promiseQueue.push(result);

    // wait for Q'd resources to resolve before letting service resolve
    if (service._promiseQueue.length) {
      service.logger.info('Wait Post Start Init...');

      // TODO: need timeout in case resource promise never resolves
      return when.all(service._promiseQueue).then(function () {
        delete service._promiseQueue;

        service.logger.info('Loaded');
        service.logger.groupEnd(' ');
      });
    } else {
      service.logger.groupEnd(' ');

      return 1;
    }
  }.bind(this)).then(function (result) {
    logger.groupEnd('Done Running All Post Start Inits');
github ohmlabs / ohm / server / ghost / core / server / models / settings.js View on Github external
var usedKeys = allSettings.models.map(function (setting) { return setting.get('key'); }),
                insertOperations = [];

            _.each(defaultSettings, function (defaultSetting, defaultSettingKey) {
                var isMissingFromDB = usedKeys.indexOf(defaultSettingKey) === -1;
                // Temporary code to deal with old databases with currentVersion settings
                if (defaultSettingKey === 'databaseVersion' && usedKeys.indexOf('currentVersion') !== -1) {
                    isMissingFromDB = false;
                }
                if (isMissingFromDB) {
                    defaultSetting.value = defaultSetting.defaultValue;
                    insertOperations.push(Settings.forge(defaultSetting).save());
                }
            });

            return when.all(insertOperations);
        });
    }
github sohamdodia / dynamodb-to-elasticsearch / index.js View on Github external
docClient.scan(scanningParameter, function (err, records) { // scanning database for getting all the records
      if (!err) {
        var recordsList = _.map(records.Items, function (record) { // for every record found
          return when.promise(function (resolve, reject) {
            recordExists(result.es, es_data, record).then(function (exists) { // check if record exists or not
              return putRecord(result.es, es_data, record, exists)
            }).then(function (record) {
              resolve(record)
            }, function (reason) {
              reject(reason)
            });
          });
        });
        // return a promise array of all records
      }
      return when.all(recordsList);
    })
  }).done(function (records) {
github bookshelf / bookshelf / test / lib / relations.js View on Github external
it('provides "attach" for creating or attaching records', function(ok) {

        var admin1 = new Admin({username: 'syncable', password: 'test'});
        var admin2 = new Admin({username: 'syncable', password: 'test'});

        when.all([admin1.save(), admin2.save()])
          .then(function() {
            return when.all([
              new Site({id: 1}).admins().attach([admin1, admin2]),
              new Site({id: 2}).admins().attach(admin2)
            ]);
          })
          .then(function(resp) {
            return when.all([
              new Site({id: 1}).admins().fetch().then(function(c) {
                c.each(function(m) {
                  equal(m.hasChanged(), false);
                });
                equal(c.at(0).pivot.get('item'), 'test');
                equal(c.length, 2);
              }),
              new Site({id: 2}).admins().fetch().then(function(c) {
github particle-iot / spark-cli / commands / CloudCommands.js View on Github external
var toggleAll = function (cores) {
				if (!cores || (cores.length === 0)) {
					console.log('No devices found.');
					return when.resolve();
				}
				else {
					var promises = [];
					cores.forEach(function (core) {
						if (!core.connected) {
							promises.push(when.resolve(core));
							return;
						}
						promises.push(api.signalCore(core.id, onOff));
					});
					return when.all(promises);
				}
			};
github jsantell / poet / lib / poet / utils.js View on Github external
return fs.readdir(dir).then(function (files) {
    return all(files.map(function (file) {
      var path = pathify(dir, file);
      return fs.stat(path).then(function (stats) {
        return stats.isDirectory() ?
          getPostPaths(path) :
          path;
      });
    }));
  }).then(function (files) {
    return _.flatten(files);
github flint-bot / flint / lib / flint.js View on Github external
var membership = this.getMemberships(message.roomId)
        .then(memberships => _.find(memberships, {'personId': message.personId}))
        .then(membership => {

          trigger.personMembership = membership;

          return when(true);
        });

      var files = this.parseFile(message)
        .then(message => {
           trigger.files = message.files || false;
           return when(true);
        });

      return when.all([room, person, membership, files])
        .then(() => when(trigger));
    });
};
github cambecc / earth / server / oscar-update.js View on Github external
var args = util.format("%s %s -o %s %s", GRIB2JSON_FLAGS, recipe.filter, tempPath, productPath);
        return tool.grib2json(args, process.stdout, process.stderr).then(function(returnCode) {
            if (returnCode !== 0) {
                log.info(util.format("grib2json failed (%s): %s", returnCode, productPath));
                return when.reject(returnCode);
            }
            log.info("processing: " + tempPath);
            var processed = processLayer(recipe, tempPath);
            var layer = processed.layer, layerPath = layer.path(opt.layerHome);
            mkdirp.sync(layer.dir(opt.layerHome));
            fs.writeFileSync(layerPath, JSON.stringify(processed.data, null, INDENT), {encoding: "utf8"});
            log.info("successfully built: " + layerPath);
            return layer;
        });
    });
    return when.all(layers);
}
github QubitProducts / cherrytree / examples / cherry-pick / app / app.js View on Github external
router.use((transition) => {
  return when.all(transition.routes.map((route) => {
    if (route.RouteHandler.fetchData) {
      return keys.all(route.RouteHandler.fetchData(transition.params, transition))
    }
  }))
})