Skip to content

Commit edec730

Browse files
ronagtargos
authored andcommitted
stream: add writableAborted
PR-URL: #40802 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 7778ebe commit edec730

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

doc/api/stream.md

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

589+
##### `writable.writableAborted`
590+
591+
<!-- YAML
592+
added: REPLACEME
593+
-->
594+
595+
> Stability: 1 - Experimental
596+
597+
* {boolean}
598+
599+
Returns whether the stream was destroyed or errored before emitting `'finish'`.
600+
589601
##### `writable.writableEnded`
590602

591603
<!-- YAML

lib/internal/streams/writable.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,18 @@ ObjectDefineProperties(Writable.prototype, {
849849
get() {
850850
return this._writableState && this._writableState.length;
851851
}
852-
}
852+
},
853+
854+
writableAborted: {
855+
enumerable: false,
856+
get: function() {
857+
return !!(
858+
this._writableState.writable !== false &&
859+
(this._writableState.destroyed || this._writableState.errored) &&
860+
!this._writableState.finished
861+
);
862+
}
863+
},
853864
});
854865

855866
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)