Last active
July 19, 2016 21:45
-
-
Save freaktechnik/3147bac85a825830d82496788218067c to your computer and use it in GitHub Desktop.
Makes sure setTimeout waits long enough.
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
| function ensureSetTimeout(cb, s) { | |
| var callTime = Date.now(); | |
| setTimeout(function() { | |
| var cbTime = Date.now(); | |
| if(cbTime - s == callTime) | |
| cb(); | |
| else | |
| ensureSetTimeout(cb, s - (cbTime - callTime)) | |
| }, s); | |
| } | |
| exports.ensureSetTimeout = ensureSetTimeout; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment