@@ -411,6 +411,35 @@ This is a destructive and immediate way to destroy a stream. Previous calls to
411411Use ` end() ` instead of destroy if data should flush before close, or wait for
412412the ` 'drain' ` event before destroying the stream.
413413
414+ ``` cjs
415+ const { Writable } = require (' stream' );
416+
417+ const myStream = new Writable ();
418+
419+ const fooErr = new Error (' foo error' );
420+ myStream .destroy (fooErr);
421+ myStream .on (' error' , (fooErr ) => console .error (fooErr .message )); // foo error
422+ ```
423+
424+ ``` cjs
425+ const { Writable } = require (' stream' );
426+
427+ const myStream = new Writable ();
428+
429+ myStream .destroy ();
430+ myStream .on (' error' , function wontHappen () {});
431+ ```
432+
433+ ``` cjs
434+ const { Writable } = require (' stream' );
435+
436+ const myStream = new Writable ();
437+ myStream .destroy ();
438+
439+ myStream .write (' foo' , (error ) => console .error (error .code ));
440+ // ERR_STREAM_DESTROYED
441+ ```
442+
414443Once ` destroy() ` has been called any further calls will be a no-op and no
415444further errors except from ` _destroy() ` may be emitted as ` 'error' ` .
416445
@@ -426,6 +455,16 @@ added: v8.0.0
426455
427456Is ` true ` after [ ` writable.destroy() ` ] [ writable-destroy ] has been called.
428457
458+ ``` cjs
459+ const { Writable } = require (' stream' );
460+
461+ const myStream = new Writable ();
462+
463+ console .log (myStream .destroyed ); // false
464+ myStream .destroy ();
465+ console .log (myStream .destroyed ); // true
466+ ```
467+
429468##### ` writable.end([chunk[, encoding]][, callback]) `
430469<!-- YAML
431470added: v0.9.4
0 commit comments