Last active
August 9, 2018 08:40
-
-
Save torjusti/46007b1107eaf511dcf342559651e846 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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