Skip to content

Commit

Permalink
Use util instead of creating local helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurmfgtab committed Sep 11, 2023
1 parent 4d19721 commit c1f534e
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/libs/RequestThrottle.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import CONST from '../CONST';
import {generateRandomInt} from './NumberUtils';

let requestWaitTime = 0;

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;
}
Expand Down

0 comments on commit c1f534e

Please sign in to comment.