Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

0.11: Writable stream does not emit 'finish' after a write() #6118

Closed
hueniverse opened this issue Aug 24, 2013 · 1 comment
Closed

0.11: Writable stream does not emit 'finish' after a write() #6118

hueniverse opened this issue Aug 24, 2013 · 1 comment

Comments

@hueniverse
Copy link

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');
preview.end();
preview.removeAllListeners();

In node 0.10.17:

finish

in node 0.11.6:

Note that removing the preview.write() statement fixes the issue.

@isaacs
Copy link

isaacs commented Aug 27, 2013

This is actually a bugfix in master that didn't land in v0.10 because of a semantics change.

https://gist.github.com/isaacs/6359727

In v0.10, write() and end() callbacks might be called after the finish event was emitted. In your test, it actually is emitting finish, but it's waiting until the next tick, since a write() operation is still potentially pending completion.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants