Skip to content

Commit

Permalink
stream: add writableAborted
Browse files Browse the repository at this point in the history
PR-URL: #40802
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
ronag committed Nov 18, 2021
1 parent aa394ab commit 415726b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,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;
Expand Down
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);
}

0 comments on commit 415726b

Please sign in to comment.