GeezerVison is showing github.com — stream: add writableAborted · nodejs/node@edec730
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/stream.md +12Lines changed: 12 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -586,6 +586,18 @@ added: v11.4.0 |
586 | 586 | Is `true` if it is safe to call [`writable.write()`][stream-write], which means |
587 | 587 | the stream has not been destroyed, errored or ended. |
588 | 588 |
|
| 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 | + |
589 | 601 | ##### `writable.writableEnded` |
590 | 602 |
|
591 | 603 | <!-- YAML |
|
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/streams/writable.js +12-1Lines changed: 12 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -849,7 +849,18 @@ ObjectDefineProperties(Writable.prototype, { |
849 | 849 | get() { |
850 | 850 | return this._writableState && this._writableState.length; |
851 | 851 | } |
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 | + }, |
853 | 864 | }); |
854 | 865 |
|
855 | 866 | const destroy = destroyImpl.destroy; |
|
Collapse file
Copy file name to clipboard +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +} |