diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-16 01:59:39 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-16 02:00:31 +0100 |
commit | bd65bb67e25a79b019d745b7262b2008ce2adb15 (patch) | |
tree | 89e1b032103a63737f1a703e6a943832ef261704 /node_modules/selenium-webdriver/http | |
parent | f91466595b651721690133f58ab37f977539e95b (diff) |
incrementally verify denoms
The denominations are not stored in a separate object store.
Diffstat (limited to 'node_modules/selenium-webdriver/http')
-rw-r--r-- | node_modules/selenium-webdriver/http/util.js | 154 |
1 files changed, 95 insertions, 59 deletions
diff --git a/node_modules/selenium-webdriver/http/util.js b/node_modules/selenium-webdriver/http/util.js index 7564ba85e..8662bed28 100644 --- a/node_modules/selenium-webdriver/http/util.js +++ b/node_modules/selenium-webdriver/http/util.js @@ -61,38 +61,54 @@ exports.getStatus = getStatus; * Waits for a WebDriver server to be healthy and accepting requests. * @param {string} url Base URL of the server to query. * @param {number} timeout How long to wait for the server. - * @return {!promise.Promise} A promise that will resolve when the - * server is ready. + * @param {Promise=} opt_cancelToken A promise used as a cancellation signal: + * if resolved before the server is ready, the wait will be terminated + * early with a {@link promise.CancellationError}. + * @return {!Promise} A promise that will resolve when the server is ready, or + * if the wait is cancelled. */ -exports.waitForServer = function(url, timeout) { - var ready = promise.defer(), - start = Date.now(); - checkServerStatus(); - return ready.promise; - - function checkServerStatus() { - return getStatus(url).then(status => ready.fulfill(status), onError); - } - - function onError(e) { - // Some servers don't support the status command. If they are able to - // response with an error, then can consider the server ready. - if (e instanceof error.UnsupportedOperationError) { - ready.fulfill(); - return; +exports.waitForServer = function(url, timeout, opt_cancelToken) { + return new Promise((onResolve, onReject) => { + let start = Date.now(); + + let done = false; + let resolve = (status) => { + done = true; + onResolve(status); + }; + let reject = (err) => { + done = true; + onReject(err); + }; + + if (opt_cancelToken) { + opt_cancelToken.then(_ => reject(new promise.CancellationError)); } - if (Date.now() - start > timeout) { - ready.reject( - Error('Timed out waiting for the WebDriver server at ' + url)); - } else { - setTimeout(function() { - if (ready.promise.isPending()) { - checkServerStatus(); - } - }, 50); + checkServerStatus(); + function checkServerStatus() { + return getStatus(url).then(status => resolve(status), onError); } - } + + function onError(e) { + // Some servers don't support the status command. If they are able to + // response with an error, then can consider the server ready. + if (e instanceof error.UnsupportedOperationError) { + resolve({}); + return; + } + + if (Date.now() - start > timeout) { + reject(Error('Timed out waiting for the WebDriver server at ' + url)); + } else { + setTimeout(function() { + if (!done) { + checkServerStatus(); + } + }, 50); + } + } + }); }; @@ -101,39 +117,59 @@ exports.waitForServer = function(url, timeout) { * timeout expires. * @param {string} url The URL to poll. * @param {number} timeout How long to wait, in milliseconds. - * @return {!promise.Promise} A promise that will resolve when the - * URL responds with 2xx. + * @param {Promise=} opt_cancelToken A promise used as a cancellation signal: + * if resolved before the a 2xx response is received, the wait will be + * terminated early with a {@link promise.CancellationError}. + * @return {!Promise} A promise that will resolve when a 2xx is received from + * the given URL, or if the wait is cancelled. */ -exports.waitForUrl = function(url, timeout) { - var client = new HttpClient(url), - request = new HttpRequest('GET', ''), - ready = promise.defer(), - start = Date.now(); - testUrl(); - return ready.promise; - - function testUrl() { - client.send(request).then(onResponse, onError); - } - - function onError() { - if (Date.now() - start > timeout) { - ready.reject(Error( - 'Timed out waiting for the URL to return 2xx: ' + url)); - } else { - setTimeout(function() { - if (ready.promise.isPending()) { - testUrl(); - } - }, 50); +exports.waitForUrl = function(url, timeout, opt_cancelToken) { + return new Promise((onResolve, onReject) => { + let client = new HttpClient(url); + let request = new HttpRequest('GET', ''); + let start = Date.now(); + + let done = false; + let resolve = () => { + done = true; + onResolve(); + }; + let reject = (err) => { + done = true; + onReject(err); + }; + + if (opt_cancelToken) { + opt_cancelToken.then(_ => reject(new promise.CancellationError)); + } + + testUrl(); + + function testUrl() { + client.send(request).then(onResponse, onError); + } + + function onError() { + if (Date.now() - start > timeout) { + reject(Error('Timed out waiting for the URL to return 2xx: ' + url)); + } else { + setTimeout(function() { + if (!done) { + testUrl(); + } + }, 50); + } } - } - function onResponse(response) { - if (!ready.promise.isPending()) return; - if (response.status > 199 && response.status < 300) { - return ready.fulfill(); + function onResponse(response) { + if (done) { + return; + } + if (response.status > 199 && response.status < 300) { + resolve(); + return; + } + onError(); } - onError(); - } + }); }; |