stream: add writableAborted

PR-URL: https://github.com/nodejs/node/pull/40802
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Robert Nagy authored and Michaël Zasso committed 2022-07-11 17:54:13 +02:00
1 parent 7778ebecaa
commit edec73032c
3 files changed
+50 -1

No files matched your search

+12
View File
@@ -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
+12 -1
View File
@@ -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;
@@ -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);
}