Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit def44c8

Browse files
cpunioncbrevik
authored andcommitted
Cancel timer when dispatch wins
1 parent 03d778c commit def44c8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/GoogleAnalyticsTracker.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,12 @@ export class GoogleAnalyticsTracker {
260260
return GoogleAnalyticsBridge.dispatch();
261261
}
262262

263+
let timer = null;
264+
263265
const withTimeout = timeout => (
264266
new Promise(resolve => {
265-
setTimeout(() => {
267+
timer = setTimeout(() => {
268+
timer = null;
266269
resolve();
267270
}, Math.min(timeout, DEFAULT_DISPATCH_TIMEOUT));
268271
})
@@ -271,6 +274,11 @@ export class GoogleAnalyticsTracker {
271274
return Promise.race([
272275
GoogleAnalyticsBridge.dispatch(),
273276
withTimeout(timeout)
274-
]);
277+
]).then(result => {
278+
if (timer) {
279+
clearTimeout(timer);
280+
}
281+
return result;
282+
});
275283
}
276284
}

0 commit comments

Comments
 (0)