diff options
Diffstat (limited to 'app/assets/javascripts/lib/utils')
-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; + } } |