Skip to content

Commit 44fc2f6

Browse files
sam-githubtargos
authored andcommitted
doc: clarify effect of stream.destroy() on write()
PR-URL: #25973 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
1 parent f71d676 commit 44fc2f6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

doc/api/stream.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,17 @@ See also: [`writable.uncork()`][].
369369
added: v8.0.0
370370
-->
371371

372-
* `error` {Error}
372+
* `error` {Error} Optional, an error to emit with `'error'` event.
373373
* Returns: {this}
374374

375-
Destroy the stream, and emit the passed `'error'` and a `'close'` event.
375+
Destroy the stream. Optionally emit an `'error'` event, and always emit
376+
a `'close'` event.
376377
After this call, the writable stream has ended and subsequent calls
377378
to `write()` or `end()` will result in an `ERR_STREAM_DESTROYED` error.
379+
This is a destructive and immediate way to destroy a stream. Previous calls to
380+
`write()` may not have drained, and may trigger an `ERR_STREAM_DESTROYED` error.
381+
Use `end()` instead of destroy if data should flush before close, or wait for
382+
the `'drain'` event before destroying the stream.
378383
Implementors should not override this method,
379384
but instead implement [`writable._destroy()`][writable-_destroy].
380385

0 commit comments

Comments
 (0)