Created
December 13, 2016 17:12
-
-
Save vetras/4fd43acffa468bd44371a9bd2f3f0adc to your computer and use it in GitHub Desktop.
This file contains 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
// see this gist as well: https://gist.github.com/sergio-fry/3917217 | |
// create the "promises" objects (deferred objects) | |
var address = $.ajax({}); | |
var tweets = $.ajax({}); | |
var facebook = $.ajax({}); | |
// wait for all to be done | |
$.when(address, tweets, facebook).then(function (addressResult, tweetsResult, facebookResult) { | |
/* all solved and the result is on each function argument */ | |
}); | |
// wait for one to be done | |
$.when(address).then(function (addressResult) { | |
/* address promise is solved and the result is on the function argument */ | |
}); | |
// when / then / done / fail ?? Here: | |
// | |
// https://stackoverflow.com/questions/5436327/jquery-deferreds-and-promises-then-vs-done | |
// | |
// The callbacks attached to done() will be fired when the deferred is resolved. | |
// The callbacks attached to fail() will be fired when the deferred is rejected. | |
// | |
// Prior to jQuery 1.8, then() was just syntactic sugar: | |
promise.then(doneCallback, failCallback); | |
// was equivalent to | |
promise.done(doneCallback).fail(failCallback); | |
// As of 1.8, then() is an alias for pipe() and returns a new promise | |
// see this for pipe: https://stackoverflow.com/questions/9583783/when-should-i-use-jquery-deferreds-then-method-and-when-should-i-use-the-pip | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment