Quellcode durchsuchen

Added function lists to gen() and fun().

Eugene Lazutkin vor 3 Jahren
Ursprung
Commit
7f89a06af4
2 geänderte Dateien mit 9 neuen und 6 gelöschten Zeilen
  1. 8 5
      src/fun.js
  2. 1 1
      src/gen.js

+ 8 - 5
src/fun.js

@@ -77,7 +77,7 @@ const collect = (collect, fns) => {
     fns = [x => x];
   }
   let flushed = false;
-  const g = async value => {
+  let g = async value => {
     if (flushed) throw Error('Call to a flushed pipe.');
     if (value !== defs.none) {
       await next(value, fns, 0, collect);
@@ -86,8 +86,9 @@ const collect = (collect, fns) => {
       await flush(fns, 0, collect);
     }
   };
-  const needToFlush = fns.some(fn => fn[defs.flushSymbol] === 1);
-  return needToFlush ? defs.flushable(g) : g;
+  const needToFlush = fns.some(fn => defs.isFlushable(fn));
+  if (needToFlush) g = defs.flushable(g);
+  return defs.setFunctionList(g, fns);
 };
 
 const asArray = (...fns) => {
@@ -100,7 +101,8 @@ const asArray = (...fns) => {
     results = null;
     return r;
   };
-  if (f[defs.flushSymbol] === 1) g = defs.flushable(g);
+  if (defs.isFlushable(f)) g = defs.flushable(g);
+  if (defs.isFunctionList(f)) defs.setFunctionList(g, f.fns);
   return g;
 };
 
@@ -116,7 +118,8 @@ const fun = (...fns) => {
       }
       return {[defs.manySymbol]: 1, values: results};
     });
-  if (f[defs.flushSymbol] === 1) g = defs.flushable(g);
+  if (defs.isFlushable(f)) g = defs.flushable(g);
+  if (defs.isFunctionList(f)) defs.setFunctionList(g, f.fns);
   return g;
 };
 

+ 1 - 1
src/gen.js

@@ -72,7 +72,7 @@ const gen = (...fns) => {
   };
   const needToFlush = fns.some(fn => fn[defs.flushSymbol] === 1);
   if (needToFlush) g = defs.flushable(g);
-  return g;
+  return defs.setFunctionList(g, fns);
 };
 
 module.exports = gen;