How to use the bluebird.each 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 epochtalk / epochtalk / scripts / tasks / plugins.js View on Github external
module.exports = function() {
  // install predefined plugins
  return Promise.each(predefinedPlugins, function(pluginName) {
    return db.plugins.exists(pluginName)
    .then(function(exists) {
      if (!exists) {
        console.log('INSTALLING ' + pluginName);
        return plugins.install(pluginName); }
    });
  })
  // get all registered plugins
  .then(db.plugins.all)
  // aggregate template hooks and template dirs
  .each(function(dbPlugin) {
    var plugin = plugins.load(dbPlugin.name);
    var hooks = plugin.templateHooks;
    var templatePath = path.join(pluginsPath, dbPlugin.name, 'templates');
    var resourcePath = path.join(pluginsPath, dbPlugin.name, 'resources');
github jspizziri / sequelize-connect / lib / discover.js View on Github external
var discover = function(paths, matcher, logger) {

  var discovered = [];

  return Promise.each(paths, function(location){

    // Recurse through the api directory and collect the models
    return dive(location, matcher, logger)
      .then(function(results){
        logger.log("debug","Flattening results");
        return _.flatten(results, true);
      })
      .filter(function(value){
        return value !== false
      })
      .then(function(results){
        logger.log("debug","Assigning filtered results to discover: "+results);
        return discovered = results;
      })
      .catch(function(err) {
        logger.log("error", err);
github algorithm-visualizer / algorithm-visualizer / src / backend / models / Hierarchy.js View on Github external
cacheContributors(files, commitAuthors) {
    return Promise.each(files, file => {
      return execute(`git --no-pager log --follow --no-merges --format="%H" "${file.path}"`, {
        cwd: this.path, stdout: null,
      }).then(stdout => {
        const output = stdout.toString().replace(/\n$/, '');
        const shas = output.split('\n').reverse();
        const contributors = [];
        for (const sha of shas) {
          const author = commitAuthors[sha];
          if (author && !contributors.find(contributor => contributor.login === author.login)) {
            contributors.push(author);
          }
        }
        file.contributors = contributors;
      });
    });
  }
github greasytortoise / alumConnect / server / controllers / userController.js View on Github external
.then(function() {
                      return Promise.each(data.groups, function(group) {
                        user.groups().attach(group);
                      });
                    });
                  })
github rain1017 / memdb / app / globalevent.js View on Github external
this.sub.on('message', function(channel, msg){
            var event = channel.slice(self.config.prefix.length);
            try{
                msg = JSON.parse(msg);
            }
            catch(err){
                self.logger.error('invalid message %s', msg);
            }

            if(!self.eventListeners.hasOwnProperty(event)){
                return P.resolve();
            }

            P.each(self.eventListeners[event], function(listener){
                return P.try(function(){
                    self.logger.debug('onEvent %s %j', event, msg);
                    return listener.apply(null, msg);
                })
                .catch(function(err){
                    self.logger.error(err.stack);
                });
            });
        });
github montagejs / mop / lib / read.js View on Github external
.then(function (names) {
        config.out.status();
        return Promise.each(names, function (name) {
            config.out.status("Reading files", name);
            var fileLocation = URL.resolve(config.location || '', Location.fromPath(name));
            var relativeLocation = URL.relative(location, fileLocation);
            return config.fs.read(name)
            .then(function (content) {
                hashBuilder.update(relativeLocation);
                hashBuilder.update(content);
                var file = new File({
                    fs: config.fs,
                    location: fileLocation,
                    relativeLocation: relativeLocation,
                    package: package,
                    path: name
                });
                package.files[relativeLocation] = file;
                config.files[fileLocation] = file;
github topcoat / topcoat / tasks / start-build.js View on Github external
function buildAllColorStops() {
  return Promise.each(colorStopNames, function(colorStop) {
    return compile(colorStop)
      .then(function(cssString) {
        postprocess(cssString, colorStop)
      })
  })
}
github binci / binci / src / lib / forwarders.js View on Github external
stopForwarders: () => {
    if (!_servers.length) return Promise.resolve()
    output.success('Halting all port forwarding')
    return Promise.each(_servers, server => {
      return new Promise(resolve => {
        server.unref()
        try {
          server.close(resolve)
        } catch (e) {
          resolve()
        }
      })
    })
    .then(() => _servers = [])
  }
github an-sh / chat-service / src / RecoveryAPI.js View on Github external
return run(this, function * () {
      const sockets = yield user.userState.getSocketsToInstance()
      yield Promise.each(_.toPairs(sockets), ([socket, instance]) => {
        if (instance === this.instanceUID) {
          if (!this.transport.getSocket(socket)) {
            return user.userState.removeSocket(socket)
          }
        }
      })
      const data = yield user.userState.getSocketsToRooms()
      const args = _.values(data)
      const rooms = _.intersection(...args)
      return Promise.each(rooms, roomName => {
        return this.state.getRoom(roomName)
          .then(room => room.roomState.hasInList('userlist', userName))
          .then(isPresent => isPresent ? null : user.removeFromRoom(roomName))
          .catchReturn()
      })
    })
  }
github TryGhost / Ghost-CLI / lib / services / index.js View on Github external
callHook(hook) {
        if (!includes(ServiceManager.allowedHooks, hook)) {
            throw new Error(`Hook ${hook} does not exist.`);
        }

        let args = toArray(arguments).slice(1);
        let hooks = this.hooks[hook] || {};

        return Promise.each(Object.keys(hooks), (serviceName) => {
            let fn = hooks[serviceName];
            return fn.apply(this.services[serviceName], args);
        });
    }