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.

31 lines
582 B
JavaScript

"use strict";
const Promise = require("bluebird");
const simpleSource = require("./");
const collect = require("@ppstreams/collect"); // FIXME: add devdep
const pipe = require("@ppstreams/pipe");
const EndOfStream = require("@ppstreams/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);
});