Emit correct event

This commit is contained in:
Jerry Kurian 2020-01-27 16:10:00 -05:00
parent 2bbc5c9e0f
commit ce2bb55b24
2 changed files with 6 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import { DuplexOptions, Duplex, Transform } from "stream"; import { DuplexOptions, Duplex, Transform, Writable } from "stream";
import { isReadable } from "../helpers"; import { isReadable } from "../helpers";
@ -48,10 +48,11 @@ class Demux extends Duplex {
...options, ...options,
transform: (d, _, cb) => { transform: (d, _, cb) => {
this.push(d); this.push(d);
cb(null, d); cb(null);
}, },
}); });
this.once("unpipe", () => this._flush());
this.on("unpipe", () => this._flush());
} }
public _read(size: number) {} public _read(size: number) {}
@ -87,7 +88,7 @@ class Demux extends Duplex {
totalEnded++; totalEnded++;
if (pipelines.length === totalEnded) { if (pipelines.length === totalEnded) {
this.push(null); this.push(null);
this.emit("finished"); this.emit("end");
} }
}); });
}); });

View File

@ -724,7 +724,7 @@ test.cb("Demux should send data events", t => {
}); });
}); });
test.cb("demux() `finish` and `end` propagates", t => { test.cb.only("demux() `finish` and `end` propagates", t => {
interface Chunk { interface Chunk {
key: string; key: string;
mapped: number[]; mapped: number[];