From 4d19721fd43b010c8f7920c6df4d4b24e115ead4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Gon=C3=A7alves?= Date: Tue, 5 Sep 2023 17:48:33 +0100 Subject: [PATCH] Converted it to ts --- src/libs/RequestThrottle.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/libs/RequestThrottle.ts b/src/libs/RequestThrottle.ts index 4725a3ad5c38..9acdc9650f05 100644 --- a/src/libs/RequestThrottle.ts +++ b/src/libs/RequestThrottle.ts @@ -1,28 +1,25 @@ -import _ from 'underscore'; import CONST from '../CONST'; let requestWaitTime = 0; -function clear() { +function clear(): void { requestWaitTime = 0; } -/** - * @returns {Number} time to wait in ms - */ +function getRandomInt(min: number, max: number): number { + return Math.floor(Math.random() * (max - min + 1)) + min; +} + function getRequestWaitTime() { if (requestWaitTime) { requestWaitTime = Math.min(requestWaitTime * 2, CONST.NETWORK.MAX_RETRY_WAIT_TIME_MS); } else { - requestWaitTime = _.random(CONST.NETWORK.MIN_RETRY_WAIT_TIME_MS, CONST.NETWORK.MAX_RANDOM_RETRY_WAIT_TIME_MS); + requestWaitTime = getRandomInt(CONST.NETWORK.MIN_RETRY_WAIT_TIME_MS, CONST.NETWORK.MAX_RANDOM_RETRY_WAIT_TIME_MS); } return requestWaitTime; } -/** - * @returns {Promise} - */ -function sleep() { +function sleep(): Promise { return new Promise((resolve) => setTimeout(resolve, getRequestWaitTime())); }