Skip to content

Commit 415726b

Browse files
committed
stream: add writableAborted
PR-URL: #40802 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent aa394ab commit 415726b

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

doc/api/stream.md

+12
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,18 @@ added: v11.4.0
596596
Is `true` if it is safe to call [`writable.write()`][stream-write], which means
597597
the stream has not been destroyed, errored or ended.
598598

599+
##### `writable.writableAborted`
600+
601+
<!-- YAML
602+
added: REPLACEME
603+
-->
604+
605+
> Stability: 1 - Experimental
606+
607+
* {boolean}
608+
609+
Returns whether the stream was destroyed or errored before emitting `'finish'`.
610+
599611
##### `writable.writableEnded`
600612

601613
<!-- YAML

lib/internal/streams/writable.js

+11
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,17 @@ ObjectDefineProperties(Writable.prototype, {
864864
return this._writableState ? this._writableState.errored : null;
865865
}
866866
},
867+
868+
writableAborted: {
869+
enumerable: false,
870+
get: function() {
871+
return !!(
872+
this._writableState.writable !== false &&
873+
(this._writableState.destroyed || this._writableState.errored) &&
874+
!this._writableState.finished
875+
);
876+
}
877+
},
867878
});
868879

869880
const destroy = destroyImpl.destroy;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const { Writable } = require('stream');
6+
7+
{
8+
const writable = new Writable({
9+
write() {
10+
}
11+
});
12+
assert.strictEqual(writable.writableAborted, false);
13+
writable.destroy();
14+
assert.strictEqual(writable.writableAborted, true);
15+
}
16+
17+
{
18+
const writable = new Writable({
19+
write() {
20+
}
21+
});
22+
assert.strictEqual(writable.writableAborted, false);
23+
writable.end();
24+
writable.destroy();
25+
assert.strictEqual(writable.writableAborted, true);
26+
}

0 commit comments

Comments
 (0)