Closed
Description
I use Chrome DevTools’ “Pause on exceptions” feature during development, which also causes Chrome to pause on rejected promises. The timer
promise at nativefontwatchrunner.js:54 is currently causing the debugger to pause on every single page load, even when fonts are loaded successfully before the timeout, because in the successful case the Promise.race()
is won by the loader
promise and the timer
promise is left to time out and be rejected in the background. This is extremely annoying!
Clearing the timeout when the race is resolved solves this issue and stops Chrome DevTools from pausing in the successful case.
I’ll submit a pull request shortly, once I’ve made sure tests are passing etc.
diff --git a/src/core/nativefontwatchrunner.js b/src/core/nativefontwatchrunner.js
index 55f360d..d6f4636 100644
--- a/src/core/nativefontwatchrunner.js
+++ b/src/core/nativefontwatchrunner.js
@@ -51,11 +51,16 @@ goog.scope(function () {
check();
});
- var timer = new Promise(function (resolve, reject) {
- setTimeout(reject, that.timeout_);
- });
+ var timeoutId = null,
+ timer = new Promise(function (resolve, reject) {
+ timeoutId = setTimeout(reject, that.timeout_);
+ });
Promise.race([timer, loader]).then(function () {
+ if (timeoutId) {
+ clearTimeout(timeoutId);
+ timeoutId = null;
+ }
that.activeCallback_(that.font_);
}, function () {
that.inactiveCallback_(that.font_);
Metadata
Metadata
Assignees
Labels
No labels