diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-03-23 15:57:03 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-03-23 15:57:03 +0000 |
commit | 14b077b7cb77fd336e75f41427fe4c6170f55a8a (patch) | |
tree | 1048bbd9d6c77e28c0d3e42a6900a677f678863f /app/assets/javascripts/lib | |
parent | d576fd82333c79b3f056f26f79e85c0eceb5704b (diff) | |
download | gitlab-ce-14b077b7cb77fd336e75f41427fe4c6170f55a8a.tar.gz |
Adds stop function so we can stop polling anytime
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r-- | app/assets/javascripts/lib/utils/poll.js | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/app/assets/javascripts/lib/utils/poll.js b/app/assets/javascripts/lib/utils/poll.js index 938cf9912a8..ad0884a784d 100644 --- a/app/assets/javascripts/lib/utils/poll.js +++ b/app/assets/javascripts/lib/utils/poll.js @@ -36,20 +36,23 @@ export default class Poll { this.options.data = options.data || {}; this.intervalHeader = 'POLL-INTERVAL'; + this.canPoll = true; } checkConditions(response) { const headers = gl.utils.normalizeHeaders(response.headers); const pollInterval = headers[this.intervalHeader]; - if (pollInterval > 0 && response.status === httpStatusCodes.OK) { - this.options.successCallback(response); + if (pollInterval > 0 && response.status === httpStatusCodes.OK && this.canPoll) { setTimeout(() => { - this.makeRequest(); + // Stop can be called in the meanwhile, so let's check again. + if (this.canPoll) { + this.makeRequest(); + } }, pollInterval); - } else { - this.options.successCallback(response); } + + this.options.successCallback(response); } makeRequest() { @@ -59,4 +62,8 @@ export default class Poll { .then(response => this.checkConditions(response)) .catch(error => errorCallback(error)); } + + stop() { + this.canPoll = false; + } } |