You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
730 B
JavaScript
41 lines
730 B
JavaScript
"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);
|
|
});
|