Last active
September 1, 2016 07:20
-
-
Save alexanderjamesking/8f299ed8a6c351ac873c7a6d9573ec65 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
/** | |
* repeats a check until the check is true or the timeout is reached | |
* returns a promise that we can return to mocha | |
*/ | |
function promisePoller(condition, | |
interval = 10, | |
timeout = 1000, | |
onTimeout = new Error("Timed out")) { | |
return new Promise(function (resolve, reject) { | |
function check() { | |
setTimeout(() => { | |
if (condition()) resolve() | |
else check() | |
}, interval) | |
} | |
setTimeout(() => { reject(onTimeout) }, timeout) | |
check() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment