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.
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Promise = require("bluebird");
|
|
|
|
const simpleSource = require("./");
|
|
|
|
const collect = require("@promistream/collect"); // FIXME: add devdep
|
|
|
|
const pipe = require("@promistream/pipe");
|
|
|
|
const EndOfStream = require("@promistream/end-of-stream");
|
|
|
|
|
|
|
|
function generateNumbers() {
|
|
|
|
let i = 0;
|
|
|
|
let max = 10;
|
|
|
|
|
|
|
|
return simpleSource({ onRequest: () => {
|
|
|
|
if (i < max) {
|
|
|
|
i += 1;
|
|
|
|
return i;
|
|
|
|
} else {
|
|
|
|
throw new EndOfStream();
|
|
|
|
}
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.try(() => {
|
|
|
|
return pipe([
|
|
|
|
generateNumbers(),
|
|
|
|
collect()
|
|
|
|
]).read();
|
|
|
|
}).then((result) => {
|
|
|
|
console.log(result);
|
|
|
|
});
|