Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Async in jQuery with nested $.when

View async.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
function A(){
promises1 = new Array();
promises2 = new Array();
for (var i = start; i < end; i++)
{
B(someUri);
}
await();
}
 
function await()
{
$.when.apply($, promises1).always(function() {
$.when.apply($, promises2).always(function() {
doSomethingToTheDataStoredInSomeGlobalVariableBelow();
});
});
}
 
function B(uri){
promises1.push($.getJSON(uri, function(data){
someCollectionFrom_data.each(function () {
promises2.push($.get(someUriFrom_this, function(data){
extractSomeStuffFrom_data_AndStoreInSomeGlobalVariable();
}));
}
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.