1'use strict'; 2 3const common = require('../common'); 4const stream = require('stream'); 5const assert = require('assert'); 6 7{ 8 const r = new stream.Readable({ 9 captureRejections: true, 10 read() { 11 } 12 }); 13 r.push('hello'); 14 r.push('world'); 15 16 const err = new Error('kaboom'); 17 18 r.on('error', common.mustCall((_err) => { 19 assert.strictEqual(err, _err); 20 assert.strictEqual(r.destroyed, true); 21 })); 22 23 r.on('data', async () => { 24 throw err; 25 }); 26} 27 28{ 29 const w = new stream.Writable({ 30 captureRejections: true, 31 highWaterMark: 1, 32 write(chunk, enc, cb) { 33 process.nextTick(cb); 34 } 35 }); 36 37 const err = new Error('kaboom'); 38 39 w.write('hello', () => { 40 w.write('world'); 41 }); 42 43 w.on('error', common.mustCall((_err) => { 44 assert.strictEqual(err, _err); 45 assert.strictEqual(w.destroyed, true); 46 })); 47 48 w.on('drain', common.mustCall(async () => { 49 throw err; 50 }, 2)); 51} 52