Skip to content

Instantly share code, notes, and snippets.

@isaacs
Last active December 21, 2015 20:09
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/6359727 to your computer and use it in GitHub Desktop.
Save isaacs/6359727 to your computer and use it in GitHub Desktop.
$ cat p.js
var stream = require('stream');
var util = require('util');
var Peek = function () {
stream.Writable.call(this);
};
util.inherits(Peek, stream.Writable);
Peek.prototype._write = function (chunk, encoding, callback) {
callback();
};
var preview = new Peek();
preview.on('finish', function () {
console.log('finish');
});
preview.write('some text', 'utf-8', function(er) {
console.log('write cb');
});
preview.end(function() {
console.log('end cb');
});
console.log('end of tick');
$ ./node p.js
end of tick
write cb
finish
end cb
$ ../node-v0.10/node p.js
finish
end of tick
write cb
end cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment