Skip to content

Instantly share code, notes, and snippets.

@mtibeica
Last active November 10, 2016 19:55
Show Gist options
  • Save mtibeica/5389437 to your computer and use it in GitHub Desktop.
Save mtibeica/5389437 to your computer and use it in GitHub Desktop.
var stream = require('stream');
var util = require('util');
function MyStream() { stream.Writable.call(this); }
util.inherits(MyStream, stream.Writable);
MyStream.prototype._write = function (chunk, encoding, callback) {
console.log("_write " + chunk.length);
callback();
}
var aStream = new MyStream();
aStream.on('finish', function () { console.log('finish emitted'); })
aStream.write('x');
aStream.end();
@mtibeica
Copy link
Author

this logs

_write 1
finish emitted

i need to do extra processing (asynchronous) after all writes are done and before finish is emitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment