11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst stream = require('stream');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci{
71cb0ef41Sopenharmony_ci  const r = new stream.Readable({
81cb0ef41Sopenharmony_ci    autoDestroy: true,
91cb0ef41Sopenharmony_ci    read() {
101cb0ef41Sopenharmony_ci      this.push('hello');
111cb0ef41Sopenharmony_ci      this.push('world');
121cb0ef41Sopenharmony_ci      this.push(null);
131cb0ef41Sopenharmony_ci    },
141cb0ef41Sopenharmony_ci    destroy: common.mustCall((err, cb) => cb())
151cb0ef41Sopenharmony_ci  });
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  let ended = false;
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  r.resume();
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  r.on('end', common.mustCall(() => {
221cb0ef41Sopenharmony_ci    ended = true;
231cb0ef41Sopenharmony_ci  }));
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  r.on('close', common.mustCall(() => {
261cb0ef41Sopenharmony_ci    assert(ended);
271cb0ef41Sopenharmony_ci  }));
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci{
311cb0ef41Sopenharmony_ci  const w = new stream.Writable({
321cb0ef41Sopenharmony_ci    autoDestroy: true,
331cb0ef41Sopenharmony_ci    write(data, enc, cb) {
341cb0ef41Sopenharmony_ci      cb(null);
351cb0ef41Sopenharmony_ci    },
361cb0ef41Sopenharmony_ci    destroy: common.mustCall((err, cb) => cb())
371cb0ef41Sopenharmony_ci  });
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci  let finished = false;
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  w.write('hello');
421cb0ef41Sopenharmony_ci  w.write('world');
431cb0ef41Sopenharmony_ci  w.end();
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  w.on('finish', common.mustCall(() => {
461cb0ef41Sopenharmony_ci    finished = true;
471cb0ef41Sopenharmony_ci  }));
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci  w.on('close', common.mustCall(() => {
501cb0ef41Sopenharmony_ci    assert(finished);
511cb0ef41Sopenharmony_ci  }));
521cb0ef41Sopenharmony_ci}
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci{
551cb0ef41Sopenharmony_ci  const t = new stream.Transform({
561cb0ef41Sopenharmony_ci    autoDestroy: true,
571cb0ef41Sopenharmony_ci    transform(data, enc, cb) {
581cb0ef41Sopenharmony_ci      cb(null, data);
591cb0ef41Sopenharmony_ci    },
601cb0ef41Sopenharmony_ci    destroy: common.mustCall((err, cb) => cb())
611cb0ef41Sopenharmony_ci  });
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci  let ended = false;
641cb0ef41Sopenharmony_ci  let finished = false;
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci  t.write('hello');
671cb0ef41Sopenharmony_ci  t.write('world');
681cb0ef41Sopenharmony_ci  t.end();
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci  t.resume();
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci  t.on('end', common.mustCall(() => {
731cb0ef41Sopenharmony_ci    ended = true;
741cb0ef41Sopenharmony_ci  }));
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_ci  t.on('finish', common.mustCall(() => {
771cb0ef41Sopenharmony_ci    finished = true;
781cb0ef41Sopenharmony_ci  }));
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci  t.on('close', common.mustCall(() => {
811cb0ef41Sopenharmony_ci    assert(ended);
821cb0ef41Sopenharmony_ci    assert(finished);
831cb0ef41Sopenharmony_ci  }));
841cb0ef41Sopenharmony_ci}
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ci{
871cb0ef41Sopenharmony_ci  const r = new stream.Readable({
881cb0ef41Sopenharmony_ci    read() {
891cb0ef41Sopenharmony_ci      r2.emit('error', new Error('fail'));
901cb0ef41Sopenharmony_ci    }
911cb0ef41Sopenharmony_ci  });
921cb0ef41Sopenharmony_ci  const r2 = new stream.Readable({
931cb0ef41Sopenharmony_ci    autoDestroy: true,
941cb0ef41Sopenharmony_ci    destroy: common.mustCall((err, cb) => cb())
951cb0ef41Sopenharmony_ci  });
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci  r.pipe(r2);
981cb0ef41Sopenharmony_ci}
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci{
1011cb0ef41Sopenharmony_ci  const r = new stream.Readable({
1021cb0ef41Sopenharmony_ci    read() {
1031cb0ef41Sopenharmony_ci      w.emit('error', new Error('fail'));
1041cb0ef41Sopenharmony_ci    }
1051cb0ef41Sopenharmony_ci  });
1061cb0ef41Sopenharmony_ci  const w = new stream.Writable({
1071cb0ef41Sopenharmony_ci    autoDestroy: true,
1081cb0ef41Sopenharmony_ci    destroy: common.mustCall((err, cb) => cb())
1091cb0ef41Sopenharmony_ci  });
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_ci  r.pipe(w);
1121cb0ef41Sopenharmony_ci}
113