Fix spawn not resolving

master
Kuba Orlik 4 years ago
parent a3d1a2bc27
commit 77ff039406

@ -33,14 +33,11 @@ export class DeferedSpawn extends Emittery {
} }
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) => { this.on("data", (data) => {
console.log("got answer from process", this.process.spawnfile);
resolve(data.toString("utf-8")); resolve(data.toString("utf-8"));
}); });
this.on("error", (err) => { this.on("error", (err) => {
console.error("Rejecting from process", this.process.spawnfile, err);
reject(err); reject(err);
}); });
this.on("end", () => resolve(null)); this.on("end", () => resolve(null));
@ -83,13 +80,13 @@ export function deferedSpawn(
err += data.toString("utf-8"); err += data.toString("utf-8");
}); });
process.on("spawn", () => { process.on("spawn", () => {
spawned = true;
resolve(emitter); resolve(emitter);
}); });
process.on("close", (code) => { process.on("close", (code) => {
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