Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: add writableAborted #40802

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
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
12 changes: 12 additions & 0 deletions doc/api/stream.md
Original file line number Diff line number Diff line change
@@ -596,6 +596,18 @@ added: v11.4.0
Is `true` if it is safe to call [`writable.write()`][stream-write], which means
the stream has not been destroyed, errored or ended.

##### `writable.writableAborted`

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental

* {boolean}

Returns whether the stream was destroyed or errored before emitting `'finish'`.

##### `writable.writableEnded`

<!-- YAML
11 changes: 11 additions & 0 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
@@ -860,6 +860,17 @@ ObjectDefineProperties(Writable.prototype, {
return this._writableState ? this._writableState.errored : null;
}
},

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

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

require('../common');
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({
write() {
}
});
assert.strictEqual(writable.writableAborted, false);
writable.end();
writable.destroy();
assert.strictEqual(writable.writableAborted, true);
Copy link
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
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

}