Explorar o código

Clean the accumulated value when a stream is finished.

Eugene Lazutkin %!s(int64=3) %!d(string=hai) anos
pai
achega
5af703a9c8
Modificáronse 1 ficheiros con 6 adicións e 1 borrados
  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 => {