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 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} 53