function test(i) {
var dfd = $.Deferred();
if(i%2 == 0) {
console.log("resolve " + i);
dfd.resolve();
} else {
console.log("failure " + i);
dfd.reject();
}
return dfd.promise();
}
function call() {
var dfd = $.Deferred();
var remain = 10;
for(var i=0;i< 10;i++){
test(i).done(function() {
if(!(--remain)) {
dfd.resolve();
}
}).fail(function() {
if(!(--remain)) {
dfd.resolve();
}
})
}
return dfd.promise();
}
call().done(function() {
console.log("all finished");
});