forked from mirrors/gecko-dev
Most of this is fixing functions that in some cases return a value but then can also run to completion without returning anything. ESLint 2 catches this where previous versions didn't. Unless there was an obvious other choice I just made these functions return undefined at the end which is effectively what already happens. MozReview-Commit-ID: DEskVIjiKDM --HG-- extra : rebase_source : 07ba1d14655f5d761624b105ef025ec88323d4d5 extra : histedit_source : 9e5ab54ce1b1a5ee1f0fb143f8d1450522455e3b
34 lines
902 B
JavaScript
34 lines
902 B
JavaScript
Cu.import("resource://gre/modules/Promise.jsm");
|
|
|
|
const SINGLE_TRY_TIMEOUT = 100;
|
|
const NUMBER_OF_TRIES = 30;
|
|
|
|
function waitForConditionPromise(condition, timeoutMsg, tryCount=NUMBER_OF_TRIES) {
|
|
let defer = Promise.defer();
|
|
let tries = 0;
|
|
function checkCondition() {
|
|
if (tries >= tryCount) {
|
|
defer.reject(timeoutMsg);
|
|
}
|
|
var conditionPassed;
|
|
try {
|
|
conditionPassed = condition();
|
|
} catch (e) {
|
|
return defer.reject(e);
|
|
}
|
|
if (conditionPassed) {
|
|
return defer.resolve();
|
|
}
|
|
tries++;
|
|
setTimeout(checkCondition, SINGLE_TRY_TIMEOUT);
|
|
return undefined;
|
|
}
|
|
setTimeout(checkCondition, SINGLE_TRY_TIMEOUT);
|
|
return defer.promise;
|
|
}
|
|
|
|
function waitForCondition(condition, nextTest, errorMsg) {
|
|
waitForConditionPromise(condition, errorMsg).then(nextTest, (reason) => {
|
|
ok(false, reason + (reason.stack ? "\n" + e.stack : ""));
|
|
});
|
|
}
|