]> git.lizzy.rs Git - rust.git/commitdiff
Code: reduce progress notification spam
authorLaurențiu Nicola <lnicola@dend.ro>
Sun, 24 Jan 2021 14:13:33 +0000 (16:13 +0200)
committerLaurențiu Nicola <lnicola@dend.ro>
Mon, 25 Jan 2021 08:05:38 +0000 (10:05 +0200)
editors/code/src/net.ts

index 1ab21e7262dc383f34ff34f14afd1d20e741b545..3e50d352c90c9ba7aceba6d89a1ddb9a2638e211 100644 (file)
@@ -99,13 +99,15 @@ export async function download(opts: DownloadOpts) {
         async (progress, _cancellationToken) => {
             let lastPercentage = 0;
             await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, (readBytes, totalBytes) => {
-                const newPercentage = (readBytes / totalBytes) * 100;
-                progress.report({
-                    message: newPercentage.toFixed(0) + "%",
-                    increment: newPercentage - lastPercentage
-                });
-
-                lastPercentage = newPercentage;
+                const newPercentage = Math.round((readBytes / totalBytes) * 100);
+                if (newPercentage !== lastPercentage) {
+                    progress.report({
+                        message: `${newPercentage.toFixed(0)}%`,
+                        increment: newPercentage - lastPercentage
+                    });
+
+                    lastPercentage = newPercentage;
+                }
             });
         }
     );