| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9f81da5 commit d627724
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -180,7 +180,7 @@ function Readable(options) { | |||
| 180 | 180 | this._destroy = options.destroy; | |
| 181 | 181 | } | |
| 182 | 182 | ||
| 183 | - Stream.call(this); | ||
| 183 | + Stream.call(this, options); | ||
| 184 | 184 | } | |
| 185 | 185 | ||
| 186 | 186 | ObjectDefineProperty(Readable.prototype, 'destroyed', { | |
@@ -223,6 +223,14 @@ Readable.prototype._destroy = function(err, cb) { | |||
| 223 | 223 | cb(err); | |
| 224 | 224 | }; | |
| 225 | 225 | ||
| 226 | + Readable.prototype[EE.captureRejectionSymbol] = function(err) { | ||
| 227 | + // TODO(mcollina): remove the destroyed if once errorEmitted lands in | ||
| 228 | + // Readable. | ||
| 229 | + if (!this.destroyed) { | ||
| 230 | + this.destroy(err); | ||
| 231 | + } | ||
| 232 | + }; | ||
| 233 | + | ||
| 226 | 234 | // Manually shove something into the read() buffer. | |
| 227 | 235 | // This returns true if the highWaterMark has not been hit yet, | |
| 228 | 236 | // similar to how Writable.write() returns true if you should | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,7 @@ module.exports = Writable; | |||
| 37 | 37 | Writable.WritableState = WritableState; | |
| 38 | 38 | ||
| 39 | 39 | const internalUtil = require('internal/util'); | |
| 40 | + const EE = require('events'); | ||
| 40 | 41 | const Stream = require('stream'); | |
| 41 | 42 | const { Buffer } = require('buffer'); | |
| 42 | 43 | const destroyImpl = require('internal/streams/destroy'); | |
@@ -250,7 +251,7 @@ function Writable(options) { | |||
| 250 | 251 | this._final = options.final; | |
| 251 | 252 | } | |
| 252 | 253 | ||
| 253 | - Stream.call(this); | ||
| 254 | + Stream.call(this, options); | ||
| 254 | 255 | } | |
| 255 | 256 | ||
| 256 | 257 | // Otherwise people can pipe Writable streams, which is just wrong. | |
@@ -782,3 +783,7 @@ Writable.prototype._undestroy = destroyImpl.undestroy; | |||
| 782 | 783 | Writable.prototype._destroy = function(err, cb) { | |
| 783 | 784 | cb(err); | |
| 784 | 785 | }; | |
| 786 | + | ||
| 787 | + Writable.prototype[EE.captureRejectionSymbol] = function(err) { | ||
| 788 | + this.destroy(err); | ||
| 789 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,8 +6,8 @@ const { | |||
| 6 | 6 | ||
| 7 | 7 | const EE = require('events'); | |
| 8 | 8 | ||
| 9 | - function Stream() { | ||
| 10 | - EE.call(this); | ||
| 9 | + function Stream(opts) { | ||
| 10 | + EE.call(this, opts); | ||
| 11 | 11 | } | |
| 12 | 12 | ObjectSetPrototypeOf(Stream.prototype, EE.prototype); | |
| 13 | 13 | ObjectSetPrototypeOf(Stream, EE); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,52 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const stream = require('stream'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + { | ||
| 8 | + const r = new stream.Readable({ | ||
| 9 | + captureRejections: true, | ||
| 10 | + read() { | ||
| 11 | + this.push('hello'); | ||
| 12 | + this.push('world'); | ||
| 13 | + this.push(null); | ||
| 14 | + } | ||
| 15 | + }); | ||
| 16 | + | ||
| 17 | + const err = new Error('kaboom'); | ||
| 18 | + | ||
| 19 | + r.on('error', common.mustCall((_err) => { | ||
| 20 | + assert.strictEqual(err, _err); | ||
| 21 | + assert.strictEqual(r.destroyed, true); | ||
| 22 | + })); | ||
| 23 | + | ||
| 24 | + r.on('data', async () => { | ||
| 25 | + throw err; | ||
| 26 | + }); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + { | ||
| 30 | + const w = new stream.Writable({ | ||
| 31 | + captureRejections: true, | ||
| 32 | + highWaterMark: 1, | ||
| 33 | + write(chunk, enc, cb) { | ||
| 34 | + cb(); | ||
| 35 | + } | ||
| 36 | + }); | ||
| 37 | + | ||
| 38 | + const err = new Error('kaboom'); | ||
| 39 | + | ||
| 40 | + w.write('hello', () => { | ||
| 41 | + w.write('world'); | ||
| 42 | + }); | ||
| 43 | + | ||
| 44 | + w.on('error', common.mustCall((_err) => { | ||
| 45 | + assert.strictEqual(err, _err); | ||
| 46 | + assert.strictEqual(w.destroyed, true); | ||
| 47 | + })); | ||
| 48 | + | ||
| 49 | + w.on('drain', common.mustCall(async () => { | ||
| 50 | + throw err; | ||
| 51 | + }, 2)); | ||
| 52 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments