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 bulk delete). The function deleteFile return a jQuery promise and resolves/rejects upon deleting the file.
function deleteFiles(filePaths)
var deferreds = $.map(fileKeys, function (val, index) {
return deleteFile(filePath);
});
$.when.apply($, deferreds).then(function (schemas) {
console.log("DONE", this, schemas);
deferred.resolve();
}, function (error) {
console.log("My ajax failed");
deferred.reject(error);
});
I am getting .reject calls on some of the files in the list (and I know they exist), so I'm thinking I might need to turn the array of filePaths into a chaining of calls, like a queue (b/c this isn't what $.when does, does it? it seems to launch them all at once). I have know idea how to do this (like .deleteFile(path1).deletePath(path2). etc when they are in an array like this.
Any help is appreciated in advance.