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