Your problem is that pendingFiles
is always empty. In createTaskForFile
, you would set it to an one-element array then, but immediately call uploadNextAsync()
which shifts it out. I guess your script might work if you shifted the file after the file has been uploaded.
However, you actually don't need this array. You can just queue the action to filesOperation
, which would be a promise representing the upload of all current files.
var filesOperation = WinJS.Promise.as();
function createTaskForFile(file) {
return filesOperation = filesOperation.then(function() {
return uploadNextAsync(file);
});
}
function uploadAsync(next) {
fileslogger.debug("Uploading " + next.name);
return fileQuery.folder.getFileAsync(next.name).then(function(file) {
return Server.sendFileAsync(file);
}).then(function() {
return filesOk += 1;
}, function(error) {
filesNok += 1;
return logger.error(error.message, error);
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…