Skip to content

Instantly share code, notes, and snippets.

@rjmunro
Created May 21, 2013 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjmunro/5623795 to your computer and use it in GitHub Desktop.
Save rjmunro/5623795 to your computer and use it in GitHub Desktop.
Deferred wrapper around setTimeout. Lets you do: $.delay(100).then(function () { // some delayed action });
/**
* Deferred wrapper around setTimeout. Lets you do:
* $.delay(100).then(function () {
* // some delayed action
* });
* @param time Delay time in ms.
* @return Deferred a promise that will complete after the time
*/
jQuery.delay = function (time) {
var dfr = jQuery.Deferred();
window.setTimeout(dfr.resolve, time);
return dfr.promise();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment