Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created September 5, 2013 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/6455434 to your computer and use it in GitHub Desktop.
Save isaacs/6455434 to your computer and use it in GitHub Desktop.
var stream = require('stream');
var assert = require('assert');
var PassThrough = stream.PassThrough;
var src = new PassThrough({ objectMode: true });
var tx = new PassThrough({ objectMode: true });
var dest = new PassThrough({ objectMode: true });
dest.on('data', function(x) {
console.log('%s %j', typeof x, x);
});
src.pipe(tx).pipe(dest);
var i = -1;
var int = setInterval(function() {
console.error('interval', i);
if (i > 10) {
src.end();
clearInterval(int);
} else {
src.write(i++);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment