Skip to content

Instantly share code, notes, and snippets.

@rjmunro rjmunro/delay.js
Created May 21, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.