How to use the q.promise 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 lsubel / amam-cordova / platforms / android / cordova / lib / emulator.js View on Github external
function adbInstallWithOptions (target, apk, opts) {
                events.emit('verbose', 'Installing apk ' + apk + ' on ' + target + '...');

                var command = 'adb -s ' + target + ' install -r "' + apk + '"';
                return Q.promise(function (resolve, reject) {
                    child_process.exec(command, opts, function (err, stdout, stderr) {
                        if (err) reject(new CordovaError('Error executing "' + command + '": ' + stderr));
                        // adb does not return an error code even if installation fails. Instead it puts a specific
                        // message to stdout, so we have to use RegExp matching to detect installation failure.
                        else if (/Failure/.test(stdout)) {
                            if (stdout.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) {
                                stdout += 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' +
                                    ' or sign and deploy the unsigned apk manually using Android tools.';
                            } else if (stdout.match(/INSTALL_FAILED_VERSION_DOWNGRADE/)) {
                                stdout += 'You\'re trying to install apk with a lower versionCode that is already installed.' +
                                    '\nEither uninstall an app or increment the versionCode.';
                            }

                            reject(new CordovaError('Failed to install apk to emulator: ' + stdout));
                        } else resolve(stdout);
                    });
github alex-shpak / keemob / platforms / android / cordova / lib / emulator.js View on Github external
function adbInstallWithOptions (target, apk, opts) {
                events.emit('verbose', 'Installing apk ' + apk + ' on ' + target + '...');

                var command = 'adb -s ' + target + ' install -r "' + apk + '"';
                return Q.promise(function (resolve, reject) {
                    child_process.exec(command, opts, function (err, stdout, stderr) {
                        if (err) reject(new CordovaError('Error executing "' + command + '": ' + stderr));
                        // adb does not return an error code even if installation fails. Instead it puts a specific
                        // message to stdout, so we have to use RegExp matching to detect installation failure.
                        else if (/Failure/.test(stdout)) {
                            if (stdout.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) {
                                stdout += 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' +
                                    ' or sign and deploy the unsigned apk manually using Android tools.';
                            } else if (stdout.match(/INSTALL_FAILED_VERSION_DOWNGRADE/)) {
                                stdout += 'You\'re trying to install apk with a lower versionCode that is already installed.' +
                                    '\nEither uninstall an app or increment the versionCode.';
                            }

                            reject(new CordovaError('Failed to install apk to emulator: ' + stdout));
                        } else resolve(stdout);
                    });
github Synbiota / GENtle2 / public / scripts / plugins / chromatograph / lib / canvas / core.js View on Github external
updateCanvasDims() {
    return Q.promise((resolve) => {

      // Updates width of $canvas to take scrollbar of $scrollingParent into account
      // this.$canvas.width(this.$scrollingChild.width());

      var width = this.$canvas[0].scrollWidth,
        height = this.$canvas[0].scrollHeight;
      this.layoutSettings.canvasDims.width = width;
      this.layoutSettings.canvasDims.height = height;

      this.artist.setDimensions(width, height);

      resolve();
    });
  }
github drses / smart-contracts / makeContractHost.js View on Github external
setup: function(contractSrc) {
      contractSrc = ''+contractSrc;
      var tokens = [];
      var argPs = [];
      var resolve;
      var resultP = Q.promise(function(r) { resolve = r; });
console.log(contractSrc);
      var contract = confine(contractSrc, {Q: Q});

      var addParam = function(i, token) {
        tokens[i] = token;
        var resolveArg;
        argPs[i] = Q.promise(function(r) { resolveArg = r; });
        m.set(token, function(allegedSrc, allegedI, arg) {
          if (contractSrc !== allegedSrc) {
            throw new Error('unexpected contract: '+contractSrc);
          }
          if (i !== allegedI) {
            throw new Error('unexpected side: '+i);
          }
          m.delete(token);
          resolveArg(arg);
github sanketbajoria / cloudconnect / src / app / tunnel / sshConnection.js View on Github external
connect(c) {
        this.config = Object.assign(this.config, c);
        ++this.__retries;

        if (this.__$connectPromise != null)
            return this.__$connectPromise;

        this.__$connectPromise = Q.promise((resolve, reject, notify) => {
            this.emit(SSHConstants.CHANNEL.SSH, SSHConstants.STATUS.BEFORECONNECT);
            if (!this.config || typeof this.config === 'function' || !this.config.host || !this.config.username) {
                reject("Invalid SSH connection configuration host/username can't be empty");
                this.__$connectPromise = null;
                return;
            }

            if (this.config.tryKeyboard && !this.config.password && typeof this.config !== 'undefined') {
                delete this.config.password;
            }

            if (this.config.identity) {
                if (fs.existsSync(this.config.identity)) {
                    this.config.privateKey = fs.readFileSync(this.config.identity);
                }
                delete this.config.identity;
github nicolaspanel / node-svm / lib / commands / evaluate.js View on Github external
function checkFileExists(file){
    return Q.promise(function (resolve) {
        fs.exists(file, resolve);
    });
}
github GeReV / mpdisco / server / cover_art.js View on Github external
_downloadCover: function(url, output) {
    var file = fs.createWriteStream(output);

    var promise = Q.promise(function(resolve, reject) {
      httpFollower.get(url, function followRedirects(res) {
        res.pipe(file);

        res.on('end', function() {
          resolve(file);
        });

        file.on('error', reject);

        res.on('error', reject);
      });
    });

    return promise;
  },
github Synbiota / GENtle2 / public / scripts / common / lib / filetypes / filetypes.js View on Github external
var readFromReadData = function(file) {
  return Q.promise(function(resolve, reject) {
    file.readData(function(str) {
      resolve({name: file.name, content: str})
    }, function() {
      reject(file.name);
    });
  });
};
github sanketbajoria / cloudconnect / src / app / tunnel / index.js View on Github external
connect(c) {
        this.config = Object.assign(this.config, c);
        ++this.__retries;
        
        if (this.__$connectPromise != null)
            return this.__$connectPromise;

        this.__$connectPromise = Q.promise((resolve, reject, notify) => {
            if (!this.config || typeof this.config === 'function' || !this.config.host || !this.config.username) {
                reject("Invalid SSH connection configuration host/username can't be empty");
                this.__$connectPromise = null;
                return;
            }

            if (this.config.tryKeyboard && !this.config.password && typeof this.config !== 'undefined') {
                delete this.config.password;
            }

            if (this.config.identity) {
                if (fs.existsSync(this.config.identity)) {
                    this.config.privateKey = fs.readFileSync(this.config.identity);
                }
                delete this.config.identity;
            }
github walkdoer / Life-Time-Tracker / node_modules / tracker / server / AchieveGoal.js View on Github external
goals.forEach(function (goal) {
                    var achieve = goal.__progress >= 100;
                    if (achieve) {
                        var promise =  Q.promise(function (resolve, reject) {
                            GoalAchievement.find({goalId: goal._id, date: date}, function (err, achieve) {
                                if (err) {
                                    return reject(err);
                                }
                                resolve({goal: goal, achieve: achieve[0]});
                            });
                        });
                        promises.push(promise);
                    }
                });
                return Q.all(promises);