MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / dispose

Function dispose

src/shared/services/stdio_service.ts:303–348  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

301 }
302
303 public async dispose(): Promise<void> {
304 this.logTraffic(`Process ${this.description} is being disposed`);
305 for (const pid of this.additionalPidsToTerminate) {
306 try {
307 this.logTraffic(`Process ${this.description} is terminating process ${pid}`);
308 process.kill(pid);
309 } catch (e: any) {
310 // TODO: Logger knows the category!
311 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
312 this.logger.error({ message: e.toString() });
313 }
314 }
315 this.additionalPidsToTerminate.length = 0;
316 try {
317 if (!this.processExited && this.process && !this.process.killed) {
318 this.logTraffic(`Process ${this.description} is terminating the main process`);
319 this.process.kill();
320 } else {
321 if (this.processExited) {
322 this.logTraffic(`Process ${this.description} skipped terminating because it had already exited`);
323 } else if (!this.process) {
324 this.logTraffic(`Process ${this.description} skipped terminating because there is no process`);
325 } else if (this.process?.killed) {
326 this.logTraffic(`Process ${this.description} skipped terminating because it was already killed`);
327 } else {
328 this.logTraffic(`Process ${this.description} skipped terminating because 🤷‍♂️`);
329 }
330 }
331 } catch {
332 // This tends to throw a lot because the shell process quit when we terminated the related
333 // process above, so just swallow the error.
334 }
335 this.process = undefined;
336
337 await disposeAllAsync(this.disposables, this.logger);
338
339 // Clear log file so if any more log events come through later, we don't
340 // create a new log file and overwrite what we had.
341 this.logFile = undefined;
342
343 if (this.logStream) {
344 this.logStream.end();
345 this.logStream = undefined;
346 this.openLogFile = undefined;
347 }
348 }
349}
350
351export interface ProcessExitCodes { code: number | null, signal: NodeJS.Signals | null }

Callers

nothing calls this directly

Calls 4

disposeAllAsyncFunction · 0.90
errorMethod · 0.65
logTrafficMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected