-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathserver-process.ts
More file actions
36 lines (32 loc) · 1.06 KB
/
server-process.ts
File metadata and controls
36 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Logger } from "../common/logging";
import * as cp from "child_process";
import { Disposable } from "vscode";
import { MessageConnection } from "vscode-jsonrpc";
/** A running query server process and its associated message connection. */
export class ServerProcess implements Disposable {
child: cp.ChildProcess;
connection: MessageConnection;
logger: Logger;
constructor(
child: cp.ChildProcess,
connection: MessageConnection,
private name: string,
logger: Logger,
) {
this.child = child;
this.connection = connection;
this.logger = logger;
}
dispose(): void {
void this.logger.log(`Stopping ${this.name}...`);
this.connection.dispose();
this.connection.end();
this.child.stdin!.end();
this.child.stderr!.destroy();
this.child.removeAllListeners();
// TODO kill the process if it doesn't terminate after a certain time limit.
// On Windows, we usually have to terminate the process before closing its stdout.
this.child.stdout!.destroy();
void this.logger.log(`Stopped ${this.name}.`);
}
}