@@ -8,9 +8,12 @@ const {
|
8 | 8 | const { Buffer } = require('buffer'); |
9 | 9 | |
10 | 10 | const { |
11 | | -ERR_INVALID_ARG_TYPE, |
12 | | -ERR_STREAM_NULL_VALUES, |
13 | | -} = require('internal/errors').codes; |
| 11 | + aggregateTwoErrors, |
| 12 | +codes: { |
| 13 | +ERR_INVALID_ARG_TYPE, |
| 14 | +ERR_STREAM_NULL_VALUES, |
| 15 | +}, |
| 16 | +} = require('internal/errors'); |
14 | 17 | |
15 | 18 | function from(Readable, iterable, opts) { |
16 | 19 | let iterator; |
@@ -43,6 +46,7 @@ function from(Readable, iterable, opts) {
|
43 | 46 | // TODO(ronag): What options should be allowed? |
44 | 47 | ...opts, |
45 | 48 | }); |
| 49 | +const originalDestroy = readable._destroy; |
46 | 50 | |
47 | 51 | // Flag to protect against _read |
48 | 52 | // being called before last iteration completion. |
@@ -64,11 +68,18 @@ function from(Readable, iterable, opts) {
|
64 | 68 | }; |
65 | 69 | |
66 | 70 | readable._destroy = function(error, cb) { |
67 | | -PromisePrototypeThen( |
68 | | -close(error), |
69 | | -() => process.nextTick(cb, error), // nextTick is here in case cb throws |
70 | | -(e) => process.nextTick(cb, e || error), |
71 | | -); |
| 71 | +originalDestroy.call(this, error, (destroyError) => { |
| 72 | +const combinedError = destroyError || error; |
| 73 | +PromisePrototypeThen( |
| 74 | +close(combinedError), |
| 75 | +// nextTick is here in case cb throws |
| 76 | +() => process.nextTick(cb, combinedError), |
| 77 | +(closeError) => process.nextTick( |
| 78 | +cb, |
| 79 | +aggregateTwoErrors(combinedError, closeError), |
| 80 | +), |
| 81 | +); |
| 82 | +}); |
72 | 83 | }; |
73 | 84 | |
74 | 85 | async function close(error) { |
|