Created
February 18, 2015 07:19
-
-
Save lislon/9e1a60b5dd4c52c64e6c 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
| client.addCommand("waitForFunc", function(checker, timeout) { | |
| if (typeof timeout === 'function') { | |
| cb = timeout | |
| timeout = this.options.waitforTimeout | |
| } | |
| return new Promise(function(fulfill, reject) { | |
| var start = new Date().getMilliseconds() | |
| var timer = setTimeout(function run() { | |
| if (!checker()) { | |
| if (new Date().getMilliseconds() > start + timeout) { | |
| reject('timeout') | |
| } | |
| timer = setTimeout(run, 100) | |
| } else { | |
| fulfill(null) | |
| } | |
| }, 100) | |
| }) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment