Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2017-02-27 17:10:40 +0300
committerFatih Acet <acetfatih@gmail.com>2017-02-27 17:10:40 +0300
commitead12a90afbff0a750883583e2474ad24f83c9d8 (patch)
tree0e4136ca37599a2ff17b82e1427aadb05741d344 /app/assets
parent9c3d21e7ac305682ca42183997908bc4dd54e4f4 (diff)
parentaa1f7de98096f5b815aa5c043146b67c91359619 (diff)
Merge branch 'improve-backoff-algo' into 'master'
Improves backoff algo with maxInterval between requests See merge request !9548
Diffstat (limited to 'app/assets')
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js.es67
1 files changed, 4 insertions, 3 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js.es6 b/app/assets/javascripts/lib/utils/common_utils.js.es6
index dbf40ec7fcf..0242350f718 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js.es6
+++ b/app/assets/javascripts/lib/utils/common_utils.js.es6
@@ -329,17 +329,18 @@
* ```
*/
w.gl.utils.backOff = (fn, timeout = 60000) => {
+ const maxInterval = 32000;
let nextInterval = 2000;
- const startTime = (+new Date());
+ const startTime = Date.now();
return new Promise((resolve, reject) => {
const stop = arg => ((arg instanceof Error) ? reject(arg) : resolve(arg));
const next = () => {
- if (new Date().getTime() - startTime < timeout) {
+ if (Date.now() - startTime < timeout) {
setTimeout(fn.bind(null, next, stop), nextInterval);
- nextInterval *= 2;
+ nextInterval = Math.min(nextInterval + nextInterval, maxInterval);
} else {
reject(new Error('BACKOFF_TIMEOUT'));
}