Skip to content

Instantly share code, notes, and snippets.

@joshuaebowling
Last active August 2, 2017 20:01
Show Gist options
  • Save joshuaebowling/d93b4344ee8f54165a748549f66b8410 to your computer and use it in GitHub Desktop.
Save joshuaebowling/d93b4344ee8f54165a748549f66b8410 to your computer and use it in GitHub Desktop.
Wait for it... a time-of-no-change based throttling pattern
var
WAIT_TIMER = 1750, // in MS
waitForItTimer,
waitForIt, whatYoureWaitingToInvoke;
whatYoureWaitingToInvoke = function _whatYoureWaitingToInvoke() {
alert(`what you're waiting for!!`);
};
waitForIt = function _waitForIt() {
window.clearTimeout(waitForItTimer);
waitForItTimer = setTimeout(() => {
whatYoureWaitingToInvoke();
}, WAIT_TIMER);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment