Skip to content

Instantly share code, notes, and snippets.

@lislon
Created February 18, 2015 07:19
Show Gist options
  • Select an option

  • Save lislon/9e1a60b5dd4c52c64e6c to your computer and use it in GitHub Desktop.

Select an option

Save lislon/9e1a60b5dd4c52c64e6c to your computer and use it in GitHub Desktop.
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