So, as mentioned by @mplungjan, it turns out that my problem was linked to an error in the code. Instead of using (() => this.downloadNextElement)
or (() => this.downloadNextElement)
, I should have used () => setTimeout(() => this.downloadNextElement(), 250)
. I even reduced the delay between downloads, without any issue. So the code ends up being:
[...]
FileUtility.downloadFile(this.application.remoteUrl + path, localPath, () => setTimeout(() => this.downloadNextElement(), 100), (downloadError) => {
logError(`Error while downloading file ${this.application.remoteUrl + path} to local path ${localPath}: ${FileUtility.getErrorText(downloadError.code)}.`);
setTimeout(() => this.downloadNextElement(), 100);
});
[...]
} else {
FileUtility.deleteFile(localPath, () => setTimeout(() => this.downloadNextElement(), 100), (deleteError) => {
logError(`Error while deleting ${localPath}: ${FileUtility.getErrorText(deleteError.code)}.`);
setTimeout(() => this.downloadNextElement(), 100);
});
}
[...]