How to use the q.try function in q

To help you get started, we’ve selected a few q 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 stanford-oval / almond-cloud / omlet / conversation.js View on Github external
Q.try(() => {
                return this._registerWithOmlet(parsed, this.account);
            }).catch((e) => {
                this.send("Sorry that did not work: " + e.message);
            }).done();
        }

        if (parsed.op !== undefined) {
            // could be another thingengine internal message, ignore it
            return;
        }

        // this is probably a pre-parsed message in SEMPRE format, used by Almond
        // to do buttons and stuff
        // pass it down to the remote if we have one, otherwise ignore it
        Q.try(() => {
            return this._tryGetRemote();
        }).then(() => {
            if (this._remote) {
                return this._remote.handleParsedCommand(text);
            }
        }).catch(function(e) {
            console.log('Failed to handle assistant command: ' + e.message);
        }).done();
    }
github OrgCurrent / Android / node / bower / lib / commands / index.js View on Github external
function command() {
        var logger = new Logger();
        var commandArgs = arguments;

        Q.try(function () {
            // call require asynchronously
            return require(id).apply(undefined, commandArgs);
        })
        .done(function (commandLogger) {
            // Forward all events to exposed logger
            commandLogger.pipe(logger);
        }, function (error) {
            logger.emit('error', error);
        });

        return logger;
    }
github stanford-oval / thingengine-core / lib / devices / paired.js View on Github external
start: function() {
        // Start watching for changes to the device database
        this._listener = this._onDeviceAdded.bind(this);
        this._devices.on('device-added', this._listener);

        if (!this._tierManager.isConnectable(Tier.SERVER) &&
            this._devices.hasDevice('thingengine-own-server'))
            this._onServerAdded(this._devices.getDevice('thingengine-own-server'));
        if (!this._tierManager.isConnectable(Tier.CLOUD) &&
            this._devices.hasDevice('thingengine-own-cloud'))
            this._onCloudAdded(this._devices.getDevice('thingengine-own-cloud'));

        // Make sure that the global tier is available
        return Q.try(function() {
            // no need to save this on the database, we would reload it at startup anyway
            return this._devices.loadOneDevice({ kind: 'thingengine',
                                                 tier: Tier.GLOBAL,
                                                 own: true }, false);
        }.bind(this)).then(function() {
            // Make sure that whatever we're running on is in the db
            if (!this._devices.hasDevice('thingengine-own-' + this._tierManager.ownTier))
                return this._addSelfToDB();
            else
                return Q();
        }.bind(this)).then(function() {
            if (!this._devices.hasDevice('thingengine-own-sabrina') &&
                this._tierManager.ownTier === Tier.CLOUD)
                return this._addSabrinaToDB();
            else
                return Q();
github stanford-oval / almond-cmdline / tests / test_network.js View on Github external
promiseLoop([1,2], initUser).then(([engine1, engine2]) => {
        console.log('Initialized, starting test');
        logfile.write(`${Date.now()}\tbegin\n`);

        return Q.try(() => {
            return promiseLoop(INSTALL_LATENCY_TESTS, (test) => installLatencyTest(engine1, engine2, test));
        }).then(() => {
            return promiseLoop(ROUND_TRIP_TIME_TEST, (test) => roundTripTimeTest(engine1, engine2, test));
        }).then(() => {
            console.log('Test complete');
            logfile.write(`${Date.now()}\tend\n`);

            return Q.all([engine1.close(), engine2.close()]);
        });
    }).then(() => {
        logfile.end();
github stanford-oval / almond-dialog-agent / lib / contact_search_dialog.js View on Github external
_makeValue(choice) {
        return Q.try(() => {
            if (this.category === ValueCategory.Contact) {
                var messaging = this.manager.messaging;
                if (!messaging.isAvailable || choice.value.startsWith(messaging.type + '-account:'))
                    return Q(Ast.Value.Entity(choice.value, 'tt:contact', choice.displayName));

                return messaging.getAccountForIdentity(choice.value).then((account) => {
                    if (account) {
                        var accountPrincipal = messaging.type + '-account:' + account;
                        console.log('Converted ' + choice.value + ' to ' + accountPrincipal);
                        return Q(Ast.Value.Entity(accountPrincipal, 'tt:contact', choice.displayName));
                    } else {
                        return Q(Ast.Value.Entity(choice.value, 'tt:contact', choice.displayName));
                    }
                });
            }
github stanford-oval / almond-cloud / scripts / thing_trainer.js View on Github external
function _process(text) {
        Q.try(function() {
            return trainer.handle(text);
        }).catch(function(e) {
            console.error('ERROR: ' + e.message);
            //console.error(e.stack);
        }).then(function() {
            rl.setPrompt(trainer.prompt);
            rl.prompt();
        }).done();
    }
github ippontech / tatami / web / node_modules / bower / lib / commands / index.js View on Github external
function withLogger(func) {
        var logger = new Logger();

        Q.try(func, logger)
        .done(function () {
            var args = [].slice.call(arguments);
            args.unshift('end');
            logger.emit.apply(logger, args);
        }, function (error) {
            logger.emit('error', error);
        });

        return logger;
    }
github AngularJS-SPA-Development / survey-gorilla / server / api / v1 / card / card.service.js View on Github external
function create(contents, user) {
  var invalid = _.findKey(contents, function(value, key) {
    return !_.some(['group', 'type', 'title', 'description', 'commentable', 'link', 'due_at', 'survey'], function(field) {
      return field === key;
    });
  });

  if (invalid) {
    return Q.try(function() {
      throw new errors.FieldInvalidError(invalid);
    });
  }

  var deferred = Q.defer();

  contents.owner = user.id;

  new Card(contents).save(function(err, card) {
    if (err) return deferred.reject(err);

    card.populate('group responses.member', function(err, card) {
      if (err) return deferred.reject(err);

      //alarm.cardPublished(card, user);
github microsoft / ghcrawler / lib / crawler.js View on Github external
_requeue(request) {
    const loopName = request.meta ? request.meta.loopName : '';
    debug(`_requeue(${loopName}:${request.toUniqueString()}): enter`);
    return Q.try(() => {
      request.attemptCount = request.attemptCount || 0;
      if (++request.attemptCount > 5) {
        return this._storeDeadletter(request, `Exceeded attempt count for ${request.type}@${request.url}`);
      }
      request.addMeta({ attempt: request.attemptCount });
      const queuable = request.createRequeuable();
      return this.queues.repush(request, queuable);
    }).then(result => {
      debug(`_requeue(${loopName}:${request.toUniqueString()}): exit (success)`);
      return result;
    });
  }

q

A library for promises (CommonJS/Promises/A,B,D)

MIT
Latest version published 7 years ago

Package Health Score

63 / 100
Full package analysis