Skip to content

Instantly share code, notes, and snippets.

@ninjascribble
Last active December 11, 2015 12:38
Show Gist options
  • Select an option

  • Save ninjascribble/4602255 to your computer and use it in GitHub Desktop.

Select an option

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!');
}
@argyleink
Copy link
Copy Markdown

works like a charm

@dnkm
Copy link
Copy Markdown

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