Skip to content

Commit

Permalink
stream: add writableAborted
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Nov 13, 2021
1 parent f217025 commit fd1f784
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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() {
}
});
assert.strictEqual(writable.writableAborted, false);
writable.end();
writable.destroy()
assert.strictEqual(writable.writableAborted, true);
}

0 comments on commit fd1f784

Please sign in to comment.