Skip to content

Instantly share code, notes, and snippets.

@ninjascribble
Last active December 11, 2015 12:38
Show Gist options
  • Save ninjascribble/4602255 to your computer and use it in GitHub Desktop.
Save ninjascribble/4602255 to your computer and use it in GitHub Desktop.
jQuery $.Deferred chaining example. jsfiddle: http://jsfiddle.net/B5eZ9/1/
var a = getPromise(50)
, b = getPromise.bind(document, 1200)
, c = getPromise.bind(document, 400);
a.then(b).then(c).done(finish);
function getPromise(ttl) {
var deferred = $.Deferred();
console.log(ttl + 'ms until resolve()');
setTimeout(deferred.resolve, ttl);
return deferred.promise();
}
function finish() {
console.log('done!');
}
@dnkm
Copy link

dnkm commented Jul 22, 2015

Nice and easy. Thanks!

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