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 authored and targos committed Jul 11, 2022
1 parent 7778ebe commit edec730
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
12 changes: 12 additions & 0 deletions doc/api/stream.md
Expand Up @@ -586,6 +586,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
13 changes: 12 additions & 1 deletion lib/internal/streams/writable.js
Expand Up @@ -849,7 +849,18 @@ ObjectDefineProperties(Writable.prototype, {
get() {
return this._writableState && this._writableState.length;
}
}
},

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
@@ -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 edec730

Please sign in to comment.