| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -401,6 +401,35 @@ This is a destructive and immediate way to destroy a stream. Previous calls to | |||
| 401 | 401 | Use `end()` instead of destroy if data should flush before close, or wait for | |
| 402 | 402 | the `'drain'` event before destroying the stream. | |
| 403 | 403 | ||
| 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 | + | ||
| 404 | 433 | Once `destroy()` has been called any further calls will be a no-op and no | |
| 405 | 434 | further errors except from `_destroy()` may be emitted as `'error'`. | |
| 406 | 435 | ||
@@ -416,6 +445,16 @@ added: v8.0.0 | |||
| 416 | 445 | ||
| 417 | 446 | Is `true` after [`writable.destroy()`][writable-destroy] has been called. | |
| 418 | 447 | ||
| 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 | + | ||
| 419 | 458 | ##### `writable.end([chunk[, encoding]][, callback])` | |
| 420 | 459 | <!-- YAML | |
| 421 | 460 | added: v0.9.4 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments