| 8 | * Kills processes and aborts further command spawning on output stream error (namely, SIGPIPE). |
| 9 | */ |
| 10 | export class OutputErrorHandler implements FlowController { |
| 11 | private readonly outputStream: Writable; |
| 12 | private readonly abortController: AbortController; |
| 13 | |
| 14 | constructor({ |
| 15 | abortController, |
| 16 | outputStream, |
| 17 | }: { |
| 18 | abortController: AbortController; |
| 19 | outputStream: Writable; |
| 20 | }) { |
| 21 | this.abortController = abortController; |
| 22 | this.outputStream = outputStream; |
| 23 | } |
| 24 | |
| 25 | handle(commands: Command[]): { commands: Command[]; onFinish: () => void } { |
| 26 | const subscription = fromSharedEvent(this.outputStream, 'error').subscribe(() => { |
| 27 | commands.forEach((command) => command.kill()); |
| 28 | |
| 29 | // Avoid further commands from spawning, e.g. if `RestartProcess` is used. |
| 30 | this.abortController.abort(); |
| 31 | }); |
| 32 | |
| 33 | return { |
| 34 | commands, |
| 35 | onFinish: () => subscription.unsubscribe(), |
| 36 | }; |
| 37 | } |
| 38 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…