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
Next Next commit
stream: add writableAborted
  • Loading branch information
ronag committed Nov 13, 2021
commit 92d6aa6ee35a7357cbb04224d13e736a7bacdd4e
11 changes: 11 additions & 0 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,17 @@ ObjectDefineProperties(Writable.prototype, {
return this._writableState ? this._writableState.errored : null;
}
},

writableAborted: {
enumerable: false,
get: function() {
return !!(
this._writableState.writable &&
(this._writableState.destroyed || this._writableState.errored) &&
!this._writableState.finished
);
}
},
});

const destroy = destroyImpl.destroy;
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-stream-writable-aborted.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const assert = require('assert');
const { Writable } = require('stream');

{
const writable = new Writable({
write() {
}
});
assert.strictEqual(writable.writableAborted, false);
writable.destroy();
assert.strictEqual(writable.writableAborted, true);
}

{
const writable = new writable({
read() {
}
Comment thread
ronag marked this conversation as resolved.
Outdated
});
assert.strictEqual(writable.writableAborted, false);
writable.end();
writable.destroy()
assert.strictEqual(writable.writableAborted, true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test also emits 'finish', should we check that writable.writableAborted is false after the 'finish' event is emitted?

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.

That shouldn't emit finish... sounds like a bug

}