Skip to content

Instantly share code, notes, and snippets.

@codegino
Created January 13, 2022 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codegino/aa6cfb654b90397e4f57e8bf8b9281ea to your computer and use it in GitHub Desktop.
Save codegino/aa6cfb654b90397e4f57e8bf8b9281ea to your computer and use it in GitHub Desktop.
Basic Throttle
function throttle (callback, limit) {
var wait = false; // Initially, we're not waiting
return function () { // We return a throttled function
if (!wait) { // If we're not waiting
callback.call(); // Execute users function
wait = true; // Prevent future invocations
setTimeout(function () { // After a period of time
wait = false; // And allow future invocations
}, limit);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment