Last active
June 29, 2019 08:38
-
-
Save jokeyrhyme/9753904 to your computer and use it in GitHub Desktop.
JavaScript polling
This file contains 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
/** | |
* @param {Function} condition a function that returns `true` or `false` | |
* @param {Number} [interval=197] the amount of time to wait between tests | |
* @param {Function} callback a function to invoke when the condition returns `true` | |
*/ | |
function waitFor(condition, interval, callback) { | |
'use strict'; | |
if (condition && condition()) { | |
callback(); | |
} else { | |
setTimeout(function () { | |
waitFor(condition, interval, callback); | |
}, interval || 197); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when Promises or Events are unavailable, this allows you to safely schedule code for the future