Bläddra i källkod

Clean the accumulated value when a stream is finished.

Eugene Lazutkin 3 år sedan
förälder
incheckning
5af703a9c8
1 ändrade filer med 6 tillägg och 1 borttagningar
  1. 6 1
      src/utils/fold.js

+ 6 - 1
src/utils/fold.js

@@ -4,7 +4,12 @@ const {none, flushable} = require('../defs');
 
 const fold = (f, acc) =>
   flushable(value => {
-    if (value === none) return acc;
+    if (value === none) {
+      // clean up acc
+      const result = acc;
+      acc = null;
+      return result;
+    }
     const result = f(acc, value);
     if (result && typeof result.then == 'function') {
       return result.then(result => {