| 53 | * Program created from a subprocess. |
| 54 | */ |
| 55 | export class SubprocessProgram implements IProgram { |
| 56 | public readonly stopped: Promise<IStopMetadata>; |
| 57 | private killed = false; |
| 58 | |
| 59 | constructor( |
| 60 | private readonly child: ChildProcess, |
| 61 | private readonly logger: ILogger, |
| 62 | private readonly killBehavior: KillBehavior, |
| 63 | ) { |
| 64 | this.stopped = new Promise((resolve, reject) => { |
| 65 | child.once('exit', code => resolve({ killed: this.killed, code: code || 0 })); |
| 66 | child.once('error', error => reject({ killed: this.killed, code: 1, error })); |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | public gotTelemetery() { |
| 71 | // no-op |
| 72 | } |
| 73 | |
| 74 | public stop(): Promise<IStopMetadata> { |
| 75 | this.killed = true; |
| 76 | killTree(this.child.pid as number, this.logger, this.killBehavior); |
| 77 | return this.stopped; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * A no-op program that never stops until stop() is called. Currently, we use |
nothing calls this directly
no outgoing calls
no test coverage detected