"use strict"; const Promise = require("bluebird"); const simpleSource = require("./"); const collect = require("@promistream/collect"); const pipe = require("@promistream/pipe"); const EndOfStream = require("@promistream/end-of-stream"); function generateNumbers() { let i = 0; let max = 10; return simpleSource(() => { if (i < max) { i += 1; return i; } else { throw new EndOfStream(); } }); } return Promise.try(() => { return pipe([ generateNumbers(), collect() ]).read(); }).then((result) => { console.log(result); let pipeline = pipe([ simpleSource(() => true), collect() ]); pipeline.abort(new Error("Oh no")); return pipeline.read(); }).then((result) => { console.log(result); });