summaryrefslogtreecommitdiff
path: root/doc/api/stream.md
diff options
context:
space:
mode:
authorMathias Buus <mathiasbuus@gmail.com>2018-01-29 19:32:34 +0100
committerMatteo Collina <hello@matteocollina.com>2018-03-06 13:31:56 +0100
commit5e3f51648ed5de36b01d53bde13fb6fb7b965667 (patch)
treea134fb92b8b846e195ea3f960131fcc9147533e6 /doc/api/stream.md
parentacac0f852a02c2b129adbc51e0bd8bd482d791af (diff)
downloadnode-new-5e3f51648ed5de36b01d53bde13fb6fb7b965667.tar.gz
stream: updated streams error handling
This improves error handling for streams in a few ways. 1. It ensures that no user defined methods (_read, _write, ...) are run after .destroy has been called. 2. It introduces an explicit error to tell the user if they are write to write, etc to the stream after it has been destroyed. 3. It makes streams always emit close as the last thing after they have been destroyed 4. Changes the default _destroy to not gracefully end streams. It also updates net, http2, zlib and fs to the new error handling. PR-URL: https://github.com/nodejs/node/pull/18438 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'doc/api/stream.md')
-rw-r--r--doc/api/stream.md19
1 files changed, 15 insertions, 4 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md
index 5db990d4d2..32e368f05f 100644
--- a/doc/api/stream.md
+++ b/doc/api/stream.md
@@ -543,8 +543,10 @@ added: v8.0.0
* Returns: {this}
-Destroy the stream, and emit the passed error. After this call, the
-writable stream has ended. Implementors should not override this method,
+Destroy the stream, and emit the passed `error` and a `close` event.
+After this call, the writable stream has ended and subsequent calls
+to `write` / `end` will give an `ERR_STREAM_DESTROYED` error.
+Implementors should not override this method,
but instead implement [`writable._destroy`][writable-_destroy].
### Readable Streams
@@ -1167,8 +1169,9 @@ myReader.on('readable', () => {
added: v8.0.0
-->
-Destroy the stream, and emit `'error'`. After this call, the
-readable stream will release any internal resources.
+Destroy the stream, and emit `'error'` and `close`. After this call, the
+readable stream will release any internal resources and subsequent calls
+to `push` will be ignored.
Implementors should not override this method, but instead implement
[`readable._destroy`][readable-_destroy].
@@ -1382,6 +1385,12 @@ constructor and implement the `writable._write()` method. The
`writable._writev()` method *may* also be implemented.
#### Constructor: new stream.Writable([options])
+<!-- YAML
+changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/18438
+ description: Add `emitClose` option to specify if `close` is emitted on destroy
+-->
* `options` {Object}
* `highWaterMark` {number} Buffer level when
@@ -1395,6 +1404,8 @@ constructor and implement the `writable._write()` method. The
it becomes possible to write JavaScript values other than string,
`Buffer` or `Uint8Array` if supported by the stream implementation.
Defaults to `false`
+ * `emitClose` {boolean} Whether or not the stream should emit `close`
+ after it has been destroyed. Defaults to `true`
* `write` {Function} Implementation for the
[`stream._write()`][stream-_write] method.
* `writev` {Function} Implementation for the