Ver Fonte

storage-node: handle write backpressure to temp stream

Mokhtar Naamani há 3 anos atrás
pai
commit
370cf5fd86
1 ficheiros alterados com 11 adições e 3 exclusões
  1. 11 3
      storage-node/packages/storage/storage.js

+ 11 - 3
storage-node/packages/storage/storage.js

@@ -113,9 +113,17 @@ class StorageWriteStream extends Transform {
       }
     }
 
-    this.temp.write(chunk, (err) => {
-      callback(err)
-    })
+    // Always waiting for write flush can be slow..
+    // this.temp.write(chunk, (err) => {
+    //   callback(err)
+    // })
+
+    // Respect backpressure
+    if (!this.temp.write(chunk)) {
+      this.temp.once('drain', callback)
+    } else {
+      process.nextTick(callback)
+    }
   }
 
   _flush(callback) {