#tauri-plugin-upload v1 incorrect download progress when using Promise.all

4 messages · Page 1 of 1 (latest)

light tangle
#

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?

#

if i do this instead, it works as expected, but that means having to wait for the first download to finish before running other downloads

await startDownload(urls[0], `${APP_DATA_DIR}/cache/test.zip`);
await Promise.all(
    urls.slice(1).map((url, index) => startDownload(url, `${APP_DATA_DIR}/cache/${index}.zip`)),
);
round pollen
#

thanks for bringing this to our attention