MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / drainStdio

Function drainStdio

apps/kimi-code/src/cli/headless-exit.ts:63–77  ·  view source on GitHub ↗
(
  streams: readonly Writable[],
  timeoutMs: number = HEADLESS_STDIO_DRAIN_TIMEOUT_MS,
)

Source from the content-addressed store, hash-verified

61 * wait is bounded so a permanently-stuck consumer can't re-introduce the hang.
62 */
63export async function drainStdio(
64 streams: readonly Writable[],
65 timeoutMs: number = HEADLESS_STDIO_DRAIN_TIMEOUT_MS,
66): Promise<void> {
67 let timer: NodeJS.Timeout | undefined;
68 const timeout = new Promise<void>((resolve) => {
69 timer = setTimeout(resolve, timeoutMs);
70 timer.unref?.();
71 });
72 try {
73 await Promise.race([Promise.all(streams.map(flushStream)).then(() => undefined), timeout]);
74 } finally {
75 if (timer !== undefined) clearTimeout(timer);
76 }
77}
78
79/**
80 * Finalize a completed headless run: flush stdio, then arm the force-exit

Callers 2

finalizeHeadlessRunFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected