Skip to content

Commit fba60c7

Browse files
committed
refactor(qa): remove redundant settlement timer wrappers
1 parent 75b38a1 commit fba60c7

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

‎extensions/qa-lab/src/posix-command-settlement.ts‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,10 @@ export function createQaPosixCommandSettlement(params: QaPosixCommandSettlementP
4343
const windows = params.windowsCleanup;
4444

4545
const schedule = (fn: () => void, delay: number) => {
46-
const timer = setTimeout(() => {
47-
fn();
48-
}, delay);
46+
const timer = setTimeout(fn, delay);
4947
timers.push(timer);
5048
return timer;
5149
};
52-
const cancel = (timer: NodeJS.Timeout | undefined) => {
53-
if (timer) {
54-
clearTimeout(timer);
55-
}
56-
};
5750
// Cleanup owns only the original PGID; a descendant that calls setsid can escape it.
5851
const alive = () =>
5952
windows?.alive?.() ??
@@ -162,15 +155,15 @@ export function createQaPosixCommandSettlement(params: QaPosixCommandSettlementP
162155
};
163156
const freeze = (nextPrimary: QaPosixCommandPrimary, initialSignal = params.initialSignal) => {
164157
primary ??= nextPrimary;
165-
cancel(executionTimer);
158+
clearTimeout(executionTimer);
166159
// Every terminal path needs a drain bound: an escaped descendant can retain
167160
// inherited stdio even after the original process group is gone.
168161
armDrainDeadline();
169162
startCleanup(initialSignal);
170163
settle();
171164
};
172165
const armIdle = () => {
173-
cancel(drainIdle);
166+
clearTimeout(drainIdle);
174167
drainIdle = schedule(startCleanup, 100);
175168
};
176169
const onOutput = () => {
@@ -204,7 +197,7 @@ export function createQaPosixCommandSettlement(params: QaPosixCommandSettlementP
204197
// `exit` freezes the leader tuple; only `close` can prove stdio drained.
205198
function onExit(exitCode: number | null, nextSignal: NodeJS.Signals | null) {
206199
primary ??= { type: "exit", exitCode, signal: nextSignal };
207-
cancel(executionTimer);
200+
clearTimeout(executionTimer);
208201
armDrainDeadline();
209202
armIdle();
210203
if (cleanupStarted && !cleanupDone && !alive()) {
@@ -213,8 +206,8 @@ export function createQaPosixCommandSettlement(params: QaPosixCommandSettlementP
213206
}
214207
function onClose() {
215208
stdioDrained = true;
216-
cancel(drainIdle);
217-
cancel(drainDeadline);
209+
clearTimeout(drainIdle);
210+
clearTimeout(drainDeadline);
218211
if (!cleanupStarted && windows) {
219212
cleanupDone = true;
220213
} else if (cleanupStarted && windows?.closeCompletesCleanup) {

0 commit comments

Comments
 (0)