Created
January 23, 2014 14:21
-
-
Save 6174/8579210 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
var args = Array.prototype.slice.call(arguments, 0); | |
var condExpr = args[0], timeout = args[1], | |
poll = args[2], cb = args[3]; | |
var waitForConditionImpl = function(conditionExpr, limit, poll, cb) { | |
if ((new Date().getTime()) < limit) { | |
var res = eval(conditionExpr); | |
if (res === true ) { | |
cb(res); | |
} else { | |
setTimeout(function() { | |
waitForConditionImpl(conditionExpr, limit, poll, cb); | |
}, poll); | |
} | |
} else { | |
res = eval(conditionExpr); | |
return cb(res); | |
} | |
}; | |
var limit = (new Date().getTime()) + timeout; | |
waitForConditionImpl(condExpr, limit, poll, cb); |
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
var args = Array.prototype.slice.call(arguments, 0); | |
var code = args[0], fargs = args[1], done = args[2]; | |
var wrap = function() { | |
return eval(code); | |
}; | |
fargs.push(done); | |
wrap.apply(this, fargs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment