minor tweak to tryForTime
This commit is contained in:
parent
7f75f65b5d
commit
e884cdc5ec
1 changed files with 4 additions and 4 deletions
|
@ -85,6 +85,7 @@ define(function (require) {
|
||||||
tryForTime: function tryForTime(timeout, block) {
|
tryForTime: function tryForTime(timeout, block) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var start = Date.now();
|
var start = Date.now();
|
||||||
|
var retryDelay = 500;
|
||||||
var lastTry = 0;
|
var lastTry = 0;
|
||||||
|
|
||||||
function attempt() {
|
function attempt() {
|
||||||
|
@ -97,13 +98,12 @@ define(function (require) {
|
||||||
return Promise
|
return Promise
|
||||||
.try(block)
|
.try(block)
|
||||||
.then(function tryForTimeSuccess() {
|
.then(function tryForTimeSuccess() {
|
||||||
self.debug('tryForTime success in about ' + (lastTry - start) + ' milliseconds');
|
self.debug('tryForTime success in about ' + (lastTry - start) + ' ms');
|
||||||
return (lastTry - start);
|
return (lastTry - start);
|
||||||
})
|
})
|
||||||
.catch(function tryForTimeCatch(err) {
|
.catch(function tryForTimeCatch(err) {
|
||||||
self.debug('failed with "' + err.message + '"');
|
self.debug('tryForTime failure, retry in ' + retryDelay + 'ms - ' + err.message);
|
||||||
self.debug('trying again in 1/2 second');
|
return Promise.delay(retryDelay).then(attempt);
|
||||||
return Promise.delay(500).then(attempt);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue