@@ -401,6 +401,35 @@ This is a destructive and immediate way to destroy a stream. Previous calls to
401401Use ` end() ` instead of destroy if data should flush before close, or wait for
402402the ` 'drain' ` event before destroying the stream.
403403
404+ ``` cjs
405+ const { Writable } = require (' stream' );
406+
407+ const myStream = new Writable ();
408+
409+ const fooErr = new Error (' foo error' );
410+ myStream .destroy (fooErr);
411+ myStream .on (' error' , (fooErr ) => console .error (fooErr .message )); // foo error
412+ ```
413+
414+ ``` cjs
415+ const { Writable } = require (' stream' );
416+
417+ const myStream = new Writable ();
418+
419+ myStream .destroy ();
420+ myStream .on (' error' , function wontHappen () {});
421+ ```
422+
423+ ``` cjs
424+ const { Writable } = require (' stream' );
425+
426+ const myStream = new Writable ();
427+ myStream .destroy ();
428+
429+ myStream .write (' foo' , (error ) => console .error (error .code ));
430+ // ERR_STREAM_DESTROYED
431+ ```
432+
404433Once ` destroy() ` has been called any further calls will be a no-op and no
405434further errors except from ` _destroy() ` may be emitted as ` 'error' ` .
406435
@@ -416,6 +445,16 @@ added: v8.0.0
416445
417446Is ` true ` after [ ` writable.destroy() ` ] [ writable-destroy ] has been called.
418447
448+ ``` cjs
449+ const { Writable } = require (' stream' );
450+
451+ const myStream = new Writable ();
452+
453+ console .log (myStream .destroyed ); // false
454+ myStream .destroy ();
455+ console .log (myStream .destroyed ); // true
456+ ```
457+
419458##### ` writable.end([chunk[, encoding]][, callback]) `
420459<!-- YAML
421460added: v0.9.4
0 commit comments