Skip to content

Instantly share code, notes, and snippets.

@6174
Created January 23, 2014 14:21
Show Gist options
  • Save 6174/8579210 to your computer and use it in GitHub Desktop.
Save 6174/8579210 to your computer and use it in GitHub Desktop.
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);
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