Skip to content

Commit 9774144

Browse files
cleaned up throttle
1 parent 23e1ac4 commit 9774144

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/backend/controllers/throttle.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ export default function throttle<T extends (...args: any) => any>(
3535
let timeout: NodeJS.Timeout;
3636
// Wrap the passed-in function callback in a callback function that "throttles" (puts a limit on) the number of calls that can be made to function in a given period of time (ms)
3737
return function throttledFunc(...args: Parameters<T>): ReturnType<T> {
38-
// CASE 1: In cooldown mode and we already have a function waiting to be executed, so do nothing
38+
// CASE 1: In cooldown mode and we have a function waiting to be executed, so do nothing
3939
if (isOnCooldown && isCallQueued) return;
4040

41-
// CASE 2: In cooldown mode, but we have no functions waiting to be executed, so just make note that we now have a call waiting to be executed and return
41+
// CASE 2: In cooldown mode, but we have no functions waiting to be executed, so just make note that we now have a callback waiting to be executed and then return
4242
if (isOnCooldown) {
4343
isCallQueued = true;
4444
return;
@@ -59,9 +59,9 @@ export default function throttle<T extends (...args: any) => any>(
5959
* @returns void
6060
*/
6161
function runAfterTimeout() {
62-
// If there is callback in the queue
62+
// If there is callback in the queue, execute callback immediately
6363
if (isCallQueued) {
64-
// Execute the function callback immediately
64+
// Execute callback
6565
callback(...args);
6666
// Initiate a new cooldown period and reset the "call queue"
6767
isOnCooldown = true;
@@ -70,7 +70,7 @@ export default function throttle<T extends (...args: any) => any>(
7070
clearTimeout(timeout);
7171
setTimeout(runAfterTimeout, MIN_TIME_BETWEEN_UPDATE);
7272
}
73-
// If not callback in queue, end the cooldown period
73+
// If no callback in queue, end the cooldown period
7474
else {
7575
// End cooldown period after MIN_TIME_BETWEEN_UPDATE has passed
7676
isOnCooldown = false;

0 commit comments

Comments
 (0)