mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
stream: Guarantee ordering of 'finish' event
In synchronous Writable streams (where the _write cb is called on the current tick), the 'finish' event (and thus the end() callback) can in some cases be called before all the write() callbacks are called. Use a counter, and have stream.Transform rely on the 'prefinish' event instead of the 'finish' event. This has zero effect on most streams, but it corrects an edge case and makes it perform more deterministically, which is a Good Thing.
This commit is contained in:
parent
8a407f58b9
commit
c38ce9bc0a
3 changed files with 53 additions and 8 deletions
|
@ -125,7 +125,7 @@ function Transform(options) {
|
|||
// sync guard flag.
|
||||
this._readableState.sync = false;
|
||||
|
||||
this.once('finish', function() {
|
||||
this.once('prefinish', function() {
|
||||
if ('function' === typeof this._flush)
|
||||
this._flush(function(er) {
|
||||
done(stream, er);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue