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() {
(--remain)) {
dfd.resolve();
call().done(function() {
console.log("all finished");
});
Output result:
Copy code