11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst stream = require('stream');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci{
81cb0ef41Sopenharmony_ci  const r = new stream.Readable({
91cb0ef41Sopenharmony_ci    captureRejections: true,
101cb0ef41Sopenharmony_ci    read() {
111cb0ef41Sopenharmony_ci    }
121cb0ef41Sopenharmony_ci  });
131cb0ef41Sopenharmony_ci  r.push('hello');
141cb0ef41Sopenharmony_ci  r.push('world');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  const err = new Error('kaboom');
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  r.on('error', common.mustCall((_err) => {
191cb0ef41Sopenharmony_ci    assert.strictEqual(err, _err);
201cb0ef41Sopenharmony_ci    assert.strictEqual(r.destroyed, true);
211cb0ef41Sopenharmony_ci  }));
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  r.on('data', async () => {
241cb0ef41Sopenharmony_ci    throw err;
251cb0ef41Sopenharmony_ci  });
261cb0ef41Sopenharmony_ci}
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci{
291cb0ef41Sopenharmony_ci  const w = new stream.Writable({
301cb0ef41Sopenharmony_ci    captureRejections: true,
311cb0ef41Sopenharmony_ci    highWaterMark: 1,
321cb0ef41Sopenharmony_ci    write(chunk, enc, cb) {
331cb0ef41Sopenharmony_ci      process.nextTick(cb);
341cb0ef41Sopenharmony_ci    }
351cb0ef41Sopenharmony_ci  });
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  const err = new Error('kaboom');
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci  w.write('hello', () => {
401cb0ef41Sopenharmony_ci    w.write('world');
411cb0ef41Sopenharmony_ci  });
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  w.on('error', common.mustCall((_err) => {
441cb0ef41Sopenharmony_ci    assert.strictEqual(err, _err);
451cb0ef41Sopenharmony_ci    assert.strictEqual(w.destroyed, true);
461cb0ef41Sopenharmony_ci  }));
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  w.on('drain', common.mustCall(async () => {
491cb0ef41Sopenharmony_ci    throw err;
501cb0ef41Sopenharmony_ci  }, 2));
511cb0ef41Sopenharmony_ci}
52