Skip to content

Commit d057ecf

Browse files
committed
chore(typecheck): Listen to subprocess termination by promise rejection
1 parent 31e2ccc commit d057ecf

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

  • packages/kbn-dev-proc-runner/src

packages/kbn-dev-proc-runner/src/proc.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import stripAnsi from 'strip-ansi';
1313

1414
import execa from 'execa';
1515
import * as Rx from 'rxjs';
16-
import { tap, share, take, mergeMap, map, ignoreElements } from 'rxjs/operators';
16+
import { tap, share, take, mergeMap, map, ignoreElements, filter } from 'rxjs/operators';
1717
import chalk from 'chalk';
1818
import treeKill from 'tree-kill';
1919
import { ToolingLog } from '@kbn/tooling-log';
@@ -88,8 +88,17 @@ export function startProc(name: string, options: ProcOptions, log: ToolingLog) {
8888
const outcome$: Rx.Observable<number | null> = Rx.race(
8989
// observe first exit event
9090
Rx.fromEvent<[number, string]>(childProcess, 'exit').pipe(
91+
filter(([code]) => {
92+
if (stopCalled) {
93+
// when stop was already called, that's a graceful exit, let those events pass.
94+
return true;
95+
} else {
96+
// filtering out further interruption events to prevent `take()` from closing the stream.
97+
return code !== null;
98+
}
99+
}),
91100
take(1),
92-
map(([code, signal]) => {
101+
map(([code]) => {
93102
if (stopCalled) {
94103
return null;
95104
}
@@ -101,12 +110,6 @@ export function startProc(name: string, options: ProcOptions, log: ToolingLog) {
101110
});
102111
}
103112

104-
// A stop signal of SIGABRT indicates a self-inflicted app crash,
105-
// then we can't rely on an exit code, because it's not passed
106-
if (signal === 'SIGABRT') {
107-
throw createFailError(`[${name}] aborted ${code ? `with code: ${code}` : ''}`);
108-
}
109-
110113
return code;
111114
})
112115
),
@@ -115,6 +118,12 @@ export function startProc(name: string, options: ProcOptions, log: ToolingLog) {
115118
Rx.fromEvent(childProcess, 'error').pipe(
116119
take(1),
117120
mergeMap((err) => Rx.throwError(err))
121+
),
122+
123+
// observe a promise rejection
124+
Rx.from(childProcess).pipe(
125+
take(1),
126+
mergeMap((err) => Rx.throwError(err))
118127
)
119128
).pipe(share());
120129

0 commit comments

Comments
 (0)