How to use the es6-promise.Promise.race function in es6-promise

To help you get started, we’ve selected a few es6-promise 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 syndesisio / syndesis-ui / e2e / app.po.ts View on Github external
async login(user: User): P {
    // need to disable angular wait before check for current url because we're being redirected outside of angular
    browser.waitForAngularEnabled(false);

    this.goToUrl(AppPage.baseurl);

    // wait either for login page or loaded ipaas app
    await P.race([
      browser.wait(ExpectedConditions.presenceOf(this.rootElement), 1000, 'ipaas root element - assuming we are already logged in'),
      browser.wait(ExpectedConditions.presenceOf(element(by.css('input'))), 1000, 'Some input field - assuming we are on login page'),
    ]);

    const url = await this.currentUrl();

    if (contains(url, 'github')) {
      // we need to login on github
      await new GithubLogin().login(user);
    } else if (contains(url, browser.baseUrl)) {
      // pass - we're already logged in
    } else {
      return P.reject(`Unsupported login page ${url}`);
    }
    browser.waitForAngularEnabled(true);
    return this.goToUrl(AppPage.baseurl);
github github / fetch / test / saucelabs.js View on Github external
function check() {
    return fetchJSON({
      method: 'POST',
      hostname: 'saucelabs.com',
      path: '/rest/v1/' + process.env.SAUCE_USERNAME + '/js-tests/status',
      headers: {},
      auth: process.env.SAUCE_USERNAME + ':' + process.env.SAUCE_ACCESS_KEY
    }, obj).then(function(obj) {
      if (obj.completed === true) {
        return obj;
      } else {
        return wait(2 * 1000).then(check);
      }
    });
  }
  return Promise.race([check(), timeout(180 * 1000)]);
}).then(function(obj) {
  var test = obj['js tests'][0];
github Caltech-IPAC / firefly / src / firefly / js / ipac-firefly / ui / TargetPanelWorker.js View on Github external
var rejectFunc= null;
    var url= '/fftools/sticky/CmdSrv?objName='+objName+'&resolver=nedthensimbad&cmd=CmdResolveName';
    var searchPromise= new Promise(
        function(resolve, reject) {
            http.get(
                { path : url },
                (res) => {
                    res.on('data', (buf) =>  resolve(buf) );
                    res.on('error', (e) =>  reject(e) );
                    res.on('end', () => { });
                })
        }).then( buf => JSON.parse(buf) );
    var abortPromise= new Promise(function(resolve,reject) {
        rejectFunc= reject;
    });
    return {p:Promise.race([searchPromise,abortPromise]), rejectFunc};
};
github Caltech-IPAC / firefly / src / firefly / js / ipac-firefly / ui / model / TargetPanelModel.js View on Github external
resolve(buf);
                });

                res.on('end', function () {
                });
            }.bind(this));

        }).then(function(buf) { return JSON.parse(buf); });

        var abortPromise= new Promise(function(resolve,reject) {
            this.abortLastRequest= function() {
                reject();
            };
        }.bind(this));

        return Promise.race([workerPromise,abortPromise]);
    }