Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'RequestThrottle.js' lib to TypeScript #24807 #26808

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/libs/RequestThrottle.js → src/libs/RequestThrottle.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import _ from 'underscore';
import CONST from '../CONST';
import {generateRandomInt} from './NumberUtils';

let requestWaitTime = 0;

function clear() {
requestWaitTime = 0;
}

/**
* @returns {Number} time to wait in ms
*/
function getRequestWaitTime() {
if (requestWaitTime) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing return type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed that getRandomInt and got one from utils as recommended here, thanks though ;)

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 = generateRandomInt(CONST.NETWORK.MIN_RETRY_WAIT_TIME_MS, CONST.NETWORK.MAX_RANDOM_RETRY_WAIT_TIME_MS);
}
return requestWaitTime;
}

/**
* @returns {Promise}
*/
function sleep() {
function sleep(): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, getRequestWaitTime()));
}

Expand Down
Loading