summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-03-23 16:12:43 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-03-23 16:12:43 +0000
commit70e59559ce65daf663077421243c45e2bc0ccf49 (patch)
treecac4fee4792a07f40d75354f5b460f13e4062dcc
parent14b077b7cb77fd336e75f41427fe4c6170f55a8a (diff)
downloadgitlab-ce-70e59559ce65daf663077421243c45e2bc0ccf49.tar.gz
Clears timeout
-rw-r--r--app/assets/javascripts/lib/utils/poll.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/app/assets/javascripts/lib/utils/poll.js b/app/assets/javascripts/lib/utils/poll.js
index ad0884a784d..c30a1fcb5da 100644
--- a/app/assets/javascripts/lib/utils/poll.js
+++ b/app/assets/javascripts/lib/utils/poll.js
@@ -36,6 +36,7 @@ export default class Poll {
this.options.data = options.data || {};
this.intervalHeader = 'POLL-INTERVAL';
+ this.timeoutID = null;
this.canPoll = true;
}
@@ -44,11 +45,8 @@ export default class Poll {
const pollInterval = headers[this.intervalHeader];
if (pollInterval > 0 && response.status === httpStatusCodes.OK && this.canPoll) {
- setTimeout(() => {
- // Stop can be called in the meanwhile, so let's check again.
- if (this.canPoll) {
- this.makeRequest();
- }
+ this.timeoutID = setTimeout(() => {
+ this.makeRequest();
}, pollInterval);
}
@@ -63,7 +61,13 @@ export default class Poll {
.catch(error => errorCallback(error));
}
+ /**
+ * Stops the polling recursive chain
+ * and guarantees if the timeout is already running it won't make another request by
+ * cancelling the previously established timeout.
+ */
stop() {
this.canPoll = false;
+ clearTimeout(this.timeoutID);
}
}