Skip to content

Instantly share code, notes, and snippets.

@gurdotan
Created March 27, 2013 09:53
Show Gist options
  • Save gurdotan/5253093 to your computer and use it in GitHub Desktop.
Save gurdotan/5253093 to your computer and use it in GitHub Desktop.
jQuery Deferred objects - example
// Based on http://www.intridea.com/blog/2011/2/8/fun-with-jquery-deferred
$.wait = function(time) {
var deferred = $.Deferred(function(dfd) {
setTimeout(dfd.resolve, time);
});
// Can return susbset of Deferred object
// without any state mutating functionality:
//
// return deferred.promise()
return deferred;
}
// Example usage
$.wait(5000).then(function() {
alert("Hello from the future!");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment