Last active
February 7, 2021 23:08
-
-
Save rap0so/f907a7241b74c61f80e27a2315d296ef to your computer and use it in GitHub Desktop.
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
import waitForTrue from './waitForTrue' | |
export default waitForTrue |
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
{ | |
"name": "waitForTrue", | |
"version": "1.0.0" | |
} |
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
/** | |
* @summary Function that wait for var be ready, and when its ready it will run the callback | |
* @description Function will be reexecuted on setTimeOut until var is ready | |
* when var exists the `callback` will be executed | |
* the function usually runs by passing an global param as `variable` | |
* | |
* @param { Function } fnIsTrue - The function that should return an boolean | |
* @param { Function } callback - The callback function to be executed | |
* @param { Number } time? - Optional time to try again | |
*/ | |
function waitForTrue (fnIsTrue, callback, time) { | |
if (fnIsTrue()) { | |
return callback(); | |
} | |
setTimeout(function() { | |
waitForTrue(fnIsTrue, callback, time); | |
}, time || 50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment