-
Notifications
You must be signed in to change notification settings - Fork 1
/
svcrunner.ts
38 lines (31 loc) · 949 Bytes
/
svcrunner.ts
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
37
38
import { spawn, ChildProcess } from 'child_process';
export class SvcRunner {
private command: string;
private args: string[] | undefined;
private childProc: ChildProcess | undefined;
constructor(command: string, args?: string[]) {
this.command = command;
this.args = args;
}
public async start(): Promise<void> {
if (this.childProc != null) {
return;
}
this.childProc = spawn(this.command, this.args, {
stdio: ['pipe', 'pipe', 'pipe'],
});
return new Promise((ful, rej) => {
// Wait for initialization message
this.childProc?.stdout?.on('data', (data) => {
ful();
});
}) as Promise<void>;
}
public async stop(): Promise<void> {
if (this.childProc == null) {
return
}
this.childProc.kill();
this.childProc = undefined;
}
}