I have a function to delete a list an array of files, filePaths, by calling a single deleteFile(filePath) on each of the files in a list (some APIS I\'m using don\'t support
$.when doesn't launch anything, they were launched in your map loop. $.when simply returns a promise for an array of promises.
If you want them sequentially, use reduce:
function deleteFiles(filePaths) {
return filePaths.reduce(function(cur, next) {
return cur.then(function() {
return deleteFile(next);
});
}, $().promise());
}
If you want them sequentially, while also getting the array back with respective results:
function deleteFiles(filePaths) {
var ret = filePaths.slice(0);
return filePaths.reduce(function(cur, next, i) {
return cur.then(function() {
return ret[i] = deleteFile(next);
});
}, $().promise()).then(function(){
return $.when.apply($, ret);
})
//These don't make any sense to call in this function but sure
.then(function(schemas) {
console.log("DONE", this, schemas);
}).fail(function(error) {
console.log("My ajax failed");
});
}