Skip to content

Instantly share code, notes, and snippets.

@sukima
Last active May 20, 2019 09:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sukima/db556aa51fde15b7d37c to your computer and use it in GitHub Desktop.
Save sukima/db556aa51fde15b7d37c to your computer and use it in GitHub Desktop.
Simple jQuery $.delay promise snippit
jQuery.delay = function(ms, value) {
var defer = new jQuery.Deferred();
setTimeout(function() { defer.resolve(value); }, ms || 0);
return defer.promise();
};
@codeskyblue
Copy link

$.ajax({
  url: "http://www.example.org",
}).then($.delay(1000)).then(function(){
  console.log("After delay")
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment