Browse Source

Clean the accumulated value when a stream is finished.

Eugene Lazutkin 3 năm trước cách đây
mục cha
commit
5af703a9c8
1 tập tin đã thay đổi với 6 bổ sung1 xóa
  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 => {