Skip to content

Instantly share code, notes, and snippets.

@drewolson

drewolson/streams.js

Created Jun 21, 2013
Embed
What would you like to do?
streams2 example
var Readable = require("stream").Readable;
function buildStream() {
var i = 0;
var stream = new Readable({objectMode: true});
stream._read = function (n) {
if (i < 10) {
stream.push(i);
} else {
stream.push(null);
}
i += 1;
};
return stream;
}
stream = buildStream();
stream.on("readable", function () {
console.log(stream.read());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment