| 95 | } |
| 96 | |
| 97 | private async destroy() { |
| 98 | try { |
| 99 | for (const n of this.eventNames()) this.removeAllListeners(n); |
| 100 | if (this.process?.stdout) |
| 101 | for (const eventName of this.process.stdout.eventNames()) |
| 102 | this.process.stdout.removeAllListeners(eventName); |
| 103 | if (this.process?.stderr) |
| 104 | for (const eventName of this.process.stderr.eventNames()) |
| 105 | this.process.stderr.removeAllListeners(eventName); |
| 106 | if (this.process) |
| 107 | for (const eventName of this.process.eventNames()) |
| 108 | this.process.removeAllListeners(eventName); |
| 109 | this.process?.stdout?.destroy(); |
| 110 | this.process?.stderr?.destroy(); |
| 111 | if (this.process?.exitCode === null) { |
| 112 | this.process.kill("SIGTERM"); |
| 113 | this.process.kill("SIGKILL"); |
| 114 | } |
| 115 | } catch (error: any) { |
| 116 | console.log("[ProcessWrapper destroy() Error]", error); |
| 117 | } finally { |
| 118 | this.process = undefined; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | export function killProcess( |