Przeglądaj źródła

Update package.js

Lutz Roeder 2 lat temu
rodzic
commit
2537e860f0
1 zmienionych plików z 10 dodań i 9 usunięć
  1. 10 9
      package.js

+ 10 - 9
package.js

@@ -64,20 +64,21 @@ const request = async (url, init, status) => {
         let position = 0;
         const stream = new ReadableStream({
             start(controller) {
-                const read = () => {
-                    reader.read().then((result) => {
+                const read = async () => {
+                    try {
+                        const result = await reader.read();
                         if (result.done) {
                             clearLine();
                             controller.close();
-                            return;
+                        } else {
+                            position += result.value.length;
+                            write('  ' + position + ' bytes\r');
+                            controller.enqueue(result.value);
+                            read();
                         }
-                        position += result.value.length;
-                        write('  ' + position + ' bytes\r');
-                        controller.enqueue(result.value);
-                        read();
-                    }).catch(error => {
+                    } catch (error) {
                         controller.error(error);
-                    });
+                    }
                 };
                 read();
             }