Restart the managed child process (by killing the current, and spawning a new).
()
| 161 | |
| 162 | /** Restart the managed child process (by killing the current, and spawning a new). */ |
| 163 | public async restart(): Promise<void> { |
| 164 | if (this.process && !this._isRestarting) { |
| 165 | this.setState(ProcessState.KILLING); |
| 166 | this._isRestarting = true; |
| 167 | this.logContent(`Restarting ${this.name} process`); |
| 168 | // Replace all listeners with a single listener waiting for the process to exit |
| 169 | this.process.removeAllListeners(); |
| 170 | this.process.once('exit', (code, signal) => { |
| 171 | if (code) { this.logContent(`Old ${this.name} exited with code ${code}`); } |
| 172 | else { this.logContent(`Old ${this.name} exited with signal ${signal}`); } |
| 173 | this._isRestarting = false; |
| 174 | this.spawn(); |
| 175 | }); |
| 176 | // Kill process |
| 177 | await this.treeKill(this.process.pid); |
| 178 | this.process = undefined; |
| 179 | } else { |
| 180 | this.spawn(); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | private treeKill = async (PID: number): Promise<void> => { |
| 185 | await new Promise<void>((resolve, reject) => { |
nothing calls this directly
no test coverage detected