Skip to content

Instantly share code, notes, and snippets.

@risseraka
Created August 27, 2014 09:37
Show Gist options
  • Save risseraka/33293d21f858c2aecaf2 to your computer and use it in GitHub Desktop.
Save risseraka/33293d21f858c2aecaf2 to your computer and use it in GitHub Desktop.
var Readable = require('stream').Readable;
var readable = Readable();
var read = false;
readable._read = function () {
console.log('reading');
this.push(read ? null : '1');
read = true;
};
console.log('before on()');
readable.pause();
readable.on('data', function () {
console.log('got data in first listener');
});
readable.on('data', function () {
console.log('got data in second listener');
throw new Error('something unexpected happened!');
});
readable.on('end', function () {
console.log('end of stream');
});
console.log('after on()');
readable.resume();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment