Skip to content

Instantly share code, notes, and snippets.

@creage
Created April 25, 2014 20:44
Show Gist options
  • Save creage/11302659 to your computer and use it in GitHub Desktop.
Save creage/11302659 to your computer and use it in GitHub Desktop.
$.wait
(function ($, window, document, undefined) {
$.extend({
/*
* wait for timeout until condition returns true
*/
wait: function (conditionCallback, timeout) {
timeout = timeout || 50;
return $.Deferred(function (dfd) {
(function toExec() {
if (conditionCallback()) {
dfd.resolve();
} else setTimeout(toExec, timeout);
})();
});
}
});
}(jQuery, window, document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment