* Restarts the ongoing program.
(newParams: AnyLaunchConfiguration)
| 193 | * Restarts the ongoing program. |
| 194 | */ |
| 195 | public async restart(newParams: AnyLaunchConfiguration): Promise<void> { |
| 196 | if (!this.run) { |
| 197 | return; |
| 198 | } |
| 199 | |
| 200 | // Clear the program so that termination logic doesn't run. |
| 201 | const program = this.program; |
| 202 | if (program) { |
| 203 | this.program = undefined; |
| 204 | await program.stop(); |
| 205 | |
| 206 | const closeOk = await Promise.race([ |
| 207 | delay(2000).then(() => false), |
| 208 | Promise.all([...this.serverConnections].map(c => new Promise(r => c.onDisconnected(r)))), |
| 209 | ]); |
| 210 | |
| 211 | if (!closeOk) { |
| 212 | this.logger.warn(LogTag.RuntimeLaunch, 'Timeout waiting for server connections to close'); |
| 213 | this.closeAllConnections(); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // relaunch the program, releasing the initial cancellation token: |
| 218 | await this.launchProgram({ |
| 219 | ...this.run, |
| 220 | params: newParams ? this.resolveParams(newParams) ?? this.run.params : this.run.params, |
| 221 | context: { |
| 222 | ...this.run.context, |
| 223 | cancellationToken: this.run.params.timeout > 0 |
| 224 | ? CancellationTokenSource.withTimeout(this.run.params.timeout).token |
| 225 | : NeverCancelled, |
| 226 | }, |
| 227 | }); |
| 228 | } |
| 229 | |
| 230 | public targetList(): ITarget[] { |
| 231 | return [...this.targets.value()]; |
no test coverage detected