* Terminates the shell process.
()
| 128 | * Terminates the shell process. |
| 129 | */ |
| 130 | public async kill(): Promise<void> { |
| 131 | invariant( |
| 132 | this.id, |
| 133 | 'Failed to run "kill" on a ShellProcess: there is no process running. Did you forget to run it?' |
| 134 | ); |
| 135 | |
| 136 | /** |
| 137 | * @note Optimistically (and eagerly) transition the shell to the next state. |
| 138 | * Shell exit only fails on protocol mismatch or when it's already been killed. |
| 139 | */ |
| 140 | this.state = 'idle'; |
| 141 | |
| 142 | /** |
| 143 | * @todo I wonder if we should support a custom "exitCode" here |
| 144 | * or a signal. |
| 145 | */ |
| 146 | await this.channel.send('shell/exit', { id: this.id }).catch((error) => { |
| 147 | throw new Error(format('Failed to kill shell with ID "%s"', this.id), { cause: error }); |
| 148 | }); |
| 149 | |
| 150 | this.id = undefined; |
| 151 | } |
| 152 | } |