refactor(e2b): narrow settlement polling helper

This commit is contained in:
Tianyi Cui
2026-07-29 23:53:20 +08:00
parent 677541d123
commit e8d5599945

View File

@@ -84,10 +84,10 @@ type CommandSettlement =
| { kind: 'result'; result: CommandResult } | { kind: 'result'; result: CommandResult }
| { kind: 'error'; error: unknown } | { kind: 'error'; error: unknown }
function withinMs<T>(promise: Promise<T>, timeoutMs: number): Promise<T | undefined> { function withinMs(settlement: Promise<CommandSettlement>, timeoutMs: number): Promise<CommandSettlement | undefined> {
return new Promise<T | undefined>((resolve) => { return new Promise<CommandSettlement | undefined>((resolve) => {
const timer = setTimeout(() => { resolve(undefined) }, timeoutMs) const timer = setTimeout(() => { resolve(undefined) }, timeoutMs)
void promise.then((value) => { void settlement.then((value) => {
clearTimeout(timer) clearTimeout(timer)
resolve(value) resolve(value)
}) })
@@ -563,8 +563,8 @@ export class E2BSubprocessHandle implements SubprocessHandle {
return { exitCode, signal: null } return { exitCode, signal: null }
} }
if (completed !== undefined) return this.commandOutcome(completed) if (completed !== undefined) return this.commandOutcome(completed)
// TODO(e2b-status-watch): Replace collect/inherit polling when E2B can // TODO(e2b-status-watch): Replace collect/inherit control-plane polling
// observe direct-command exit independently of descendant-held output. // when E2B can observe direct-command exit independently of descendant-held output.
completed = await Promise.race([settlement, waitTick().then(() => undefined)]) completed = await Promise.race([settlement, waitTick().then(() => undefined)])
} }
} }