Output some loggin information

master
Kuba Orlik 4 years ago
parent 7ee6a21f38
commit cdbb47d6ef

@ -17,30 +17,42 @@ export default function simpleSpawn(
}); });
} }
class DeferedSpawn extends Emittery { export class DeferedSpawn extends Emittery {
constructor(private process: ChildProcessWithoutNullStreams) { constructor(private process: ChildProcessWithoutNullStreams) {
super(); super();
this.on("data", (data) => console.log("data", data.toString()));
} }
async waitForAnswer() { async waitForAnswer(): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.on("success", resolve); this.on("success", (data) => {
resolve(data);
});
this.on("error", reject); this.on("error", reject);
}); });
} }
async waitForNextData(): Promise<string | null> { async waitForNextData(): Promise<string | null> {
console.log(
"waiting for next data from",,
this.process.spawnargs.join(" ")
);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.on("data", (data) => resolve(data.toString("utf-8"))); this.on("data", (data) => {
this.on("error", reject); console.log("got answer from process", this.process.spawnfile);
resolve(data.toString("utf-8"));
});
this.on("error", (err) => {
console.error("Rejecting from process", this.process.spawnfile, err);
reject(err);
});
this.on("end", () => resolve(null)); this.on("end", () => resolve(null));
}); });
} }
kill() { kill() {
console.log("killing process!", this.process.spawnargs.join(" "));
process.kill(-this.process.pid); // https://stackoverflow.com/a/49842576 process.kill(-this.process.pid); // https://stackoverflow.com/a/49842576
debugger;
console.log("killed map!");
} }
write(data: string) { write(data: string) {
@ -72,6 +84,7 @@ export function deferedSpawn(
if (!spawned) { if (!spawned) {
reject(err); reject(err);
} else { } else {
console.log("!!!!!!!!!!!!!!!!!!!! PROCESS CLOSED");
if (code === 0) { if (code === 0) {
emitter.emit("success", output); emitter.emit("success", output);
} else { } else {

Loading…
Cancel
Save