i'm trying do download files simultaneously using Promise.all and display the progress % in the UI, but for some reason the progress % is always incorrect when calling download for the first time inside Promise.all
const urls = [
"https://thunderstore.io/package/download/BepInEx/BepInExPack/5.4.2100/",
"https://thunderstore.io/package/download/Evaisa/HookGenPatcher/0.0.5/",
"https://thunderstore.io/package/download/2018/LC_API/3.4.4/",
];
const startDownload = async (url: string, dest: string) => {
let sum = 0;
let progress = 0;
await download(url, dest, (current, total) => {
sum += current;
progress = Math.round((sum / total) * 100);
});
console.log(`URL: ${url} - ${progress}%`); // simplified to just show the end result
};
await Promise.all(
urls.map((url, index) => startDownload(url, `${APP_DATA_DIR}/cache/${index}.zip`)),
);
if there are 3 downloads, the progress will show 300%, then any subsequent downloads after that will also be 300%, even outside Promise.all
is there a way to fix it?