mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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:
1 parent
7778ebecaa
commit
edec73032c
3 files changed
+50
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user