Skip to content

Instantly share code, notes, and snippets.

@torjusti
Last active August 9, 2018 08:40
Show Gist options
  • Save torjusti/46007b1107eaf511dcf342559651e846 to your computer and use it in GitHub Desktop.
Save torjusti/46007b1107eaf511dcf342559651e846 to your computer and use it in GitHub Desktop.
/**
* Create a function which will call the callback function
* after the given amount of milliseconds has passed since
* the last time the callback function was called.
*/
const idle = (callback, delay) => {
let handle;
return () => {
if (handle) {
clearTimeout(handle);
}
handle = setTimeout(callback, delay);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment