Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: comments
  • Loading branch information
ronag committed Apr 15, 2020
commit 469766e1b9f69c6f0cf6cc73d925c29cdce4394e
2 changes: 1 addition & 1 deletion lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ function callFinal(stream, state) {
state.prefinished = true;
stream.emit('prefinish');
// Backwards compat. Don't check state.sync here.
// Some stream assume 'finish' will be emitted
// Some streams assume 'finish' will be emitted
// asynchronously relative to _final callback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth to revisit once _construct PR lands.

@ronag ronag Apr 11, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to support the following commonly used pattern:

_final(cb) (
  if (!this.ready) {
    this.once('ready', () => this._final(cb)) // Unfortunately not wrapped in a nextTick
  }
  // cleanup...
  cb();
}

state.pendingcb++;
process.nextTick(finish, stream, state);
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-stream-writable-finished.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const assert = require('assert');
}

{
// Emit finish asynchronously
// Emit finish asynchronously.

const w = new Writable({
write(chunk, encoding, cb) {
Expand All @@ -43,7 +43,7 @@ const assert = require('assert');
}

{
// Emit prefinish synchronously
// Emit prefinish synchronously.

const w = new Writable({
write(chunk, encoding, cb) {
Expand All @@ -60,7 +60,7 @@ const assert = require('assert');
}

{
// Emit prefinish synchronously w/ final
// Emit prefinish synchronously w/ final.

const w = new Writable({
write(chunk, encoding, cb) {
Expand All @@ -81,7 +81,7 @@ const assert = require('assert');


{
// Call _final synchronouslyl
// Call _final synchronously.

let sync = true;
const w = new Writable({
Expand Down