Or you can make a count-down latch of some kind:
var num_results = 3;
var results = []
var makeCallback = function(index) {
return function(response) {
num_results -= 1;
results[index] = response;
if (num_results > 0) {
return;
}
// actually do stuff here, all results are loaded.
};
};
$.get("/a", makeCallback(0));
$.get("/b", makeCallback(1));
$.get("/c", makeCallback(2));
// etc
It's also not hard to make a generic latch-producing function so you can just write stuff like: var l = makeLatch(callback);
$.get("/a", l());
$.get("/b", l());
$.get("/c", l());