fix: flush CLI stdio before forced exit
This commit is contained in:
parent
9fe947a6be
commit
0b3ba2b7d5
13
src/cli.ts
13
src/cli.ts
@ -385,7 +385,7 @@ function flushWriteStream(stream: NodeJS.WriteStream, timeoutMs: number): Promis
|
||||
let settled = false;
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
const finish = () => {
|
||||
const resolveFlush = () => {
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
@ -395,10 +395,17 @@ function flushWriteStream(stream: NodeJS.WriteStream, timeoutMs: number): Promis
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
const finish = () => {
|
||||
stream.off('error', finish);
|
||||
resolveFlush();
|
||||
};
|
||||
|
||||
timeout = setTimeout(finish, timeoutMs);
|
||||
timeout = setTimeout(resolveFlush, timeoutMs);
|
||||
stream.once('error', finish);
|
||||
try {
|
||||
stream.write('', finish);
|
||||
stream.write('', () => {
|
||||
setImmediate(finish);
|
||||
});
|
||||
} catch {
|
||||
finish();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user