asStreamTest.js 802 B

123456789101112131415161718192021222324252627
  1. const {PassThrough} = require('stream');
  2. const defs = require('../../src/defs');
  3. const asStream = require('../../src/AsStream');
  4. const s = asStream(x => x * x);
  5. // const s = asStream(async x => x * x);
  6. // const s = asStream(function* (x) { for (let i = 0; i < x; ++i) yield i; });
  7. // const s = asStream(async function* (x) { for (let i = 0; i < x; ++i) yield i; });
  8. // const s = asStream(x => defs.none);
  9. // const s = asStream(x => defs.finalValue(42));
  10. // const s = asStream(x => defs.many(['a', x, 'b']));
  11. // const s = asStream(x => defs.stop);
  12. const h = new PassThrough({writableObjectMode: true, readableObjectMode: true});
  13. const p = h.pipe(s);
  14. p.on('data', data => console.log('DATA:', data));
  15. p.on('end', () => console.log('END'));
  16. h.write(1);
  17. h.write(2);
  18. h.write(3);
  19. h.write(4);
  20. h.end();