From 4d7ff20a4ecf01c66db21bc8f69abc25e75f72f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Gon=C3=A7alves?= Date: Tue, 5 Sep 2023 17:39:08 +0100 Subject: [PATCH 1/4] Converted file from .js to .ts --- src/libs/{RequestThrottle.js => RequestThrottle.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/libs/{RequestThrottle.js => RequestThrottle.ts} (100%) diff --git a/src/libs/RequestThrottle.js b/src/libs/RequestThrottle.ts similarity index 100% rename from src/libs/RequestThrottle.js rename to src/libs/RequestThrottle.ts 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 2/4] 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())); } From c1f534ec42ad59ed15199060240598e1467d7b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Gon=C3=A7alves?= Date: Mon, 11 Sep 2023 12:08:12 +0100 Subject: [PATCH 3/4] Use util instead of creating local helper function --- src/libs/RequestThrottle.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libs/RequestThrottle.ts b/src/libs/RequestThrottle.ts index 9acdc9650f05..7a9c244e2034 100644 --- a/src/libs/RequestThrottle.ts +++ b/src/libs/RequestThrottle.ts @@ -1,4 +1,5 @@ import CONST from '../CONST'; +import {generateRandomInt} from './NumberUtils'; let requestWaitTime = 0; @@ -6,15 +7,11 @@ function clear(): void { requestWaitTime = 0; } -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 = getRandomInt(CONST.NETWORK.MIN_RETRY_WAIT_TIME_MS, CONST.NETWORK.MAX_RANDOM_RETRY_WAIT_TIME_MS); + requestWaitTime = generateRandomInt(CONST.NETWORK.MIN_RETRY_WAIT_TIME_MS, CONST.NETWORK.MAX_RANDOM_RETRY_WAIT_TIME_MS); } return requestWaitTime; } From ce0a5884e0ea85240fc970d81293d5b8679b94d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Gon=C3=A7alves?= Date: Mon, 11 Sep 2023 16:25:44 +0100 Subject: [PATCH 4/4] Removed unnecessary return type --- src/libs/RequestThrottle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/RequestThrottle.ts b/src/libs/RequestThrottle.ts index 7a9c244e2034..8f9a85dcedb5 100644 --- a/src/libs/RequestThrottle.ts +++ b/src/libs/RequestThrottle.ts @@ -3,7 +3,7 @@ import {generateRandomInt} from './NumberUtils'; let requestWaitTime = 0; -function clear(): void { +function clear() { requestWaitTime = 0; }