Pārlūkot izejas kodu

emit 'close' signal when no more input data will be consumed

this allows client to know when the network data is completely transferred, before consuming it
Gil Pedersen 12 gadi atpakaļ
vecāks
revīzija
c35c837ec4
1 mainītis faili ar 8 papildinājumiem un 3 dzēšanām
  1. 8 3
      lib/uristream.js

+ 8 - 3
lib/uristream.js

@@ -134,12 +134,17 @@ function setupHttp(uri, options, dst) {
         if (err || failed) return failOrRetry(err);
         debug('done fetching uri', uri);
         dst.push(null);
+
+        dst.closed = true;
+        dst.emit('close');
       });
 
       // allow aborting the request
-      dst.abort = function() {
-        tries = 0;
-        req.abort();
+      dst.abort = function(reason) {
+        if (!dst.closed) {
+          tries = 0;
+          req.abort();
+        }
       }
 
       // forward all future errors to response stream