Created
May 21, 2013 22:31
-
-
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
});
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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