MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / throttle

Function throttle

scripts/web_timer.js:510–524  ·  view source on GitHub ↗
(mainFunction, delay)

Source from the content-addressed store, hash-verified

508}
509// https://dev.to/jeetvora331/throttling-in-javascript-easiest-explanation-1081
510function throttle(mainFunction, delay) {
511 let timerFlag = null; // Variable to keep track of the timer
512
513 // Returning a throttled version
514 return (...args) => {
515 if (timerFlag === null) {
516 // If there is no timer currently running
517 mainFunction(...args); // Execute the main function
518 timerFlag = setTimeout(() => {
519 // Set a timer to clear the timerFlag after the specified delay
520 timerFlag = null; // Clear the timerFlag to allow the main function to be executed again
521 }, delay);
522 }
523 };
524}
525const backup = () => {
526 // export data from https://chrome.google.com/webstore/detail/ppaojnbmmaigjmlpjaldnkgnklhicppk
527 (async () => {

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected