MCPcopy
hub / github.com/claude-code-best/claude-code / peekForStdinData

Function peekForStdinData

src/utils/process.ts:49–67  ·  view source on GitHub ↗
(
  stream: NodeJS.EventEmitter,
  ms: number,
)

Source from the content-addressed store, hash-verified

47// Returns true on timeout, false on end. Used by -p mode to distinguish a
48// real pipe producer from an inherited-but-idle parent stdin.
49export function peekForStdinData(
50 stream: NodeJS.EventEmitter,
51 ms: number,
52): Promise<boolean> {
53 return new Promise<boolean>(resolve => {
54 const done = (timedOut: boolean) => {
55 clearTimeout(peek)
56 stream.off('end', onEnd)
57 stream.off('data', onFirstData)
58 void resolve(timedOut)
59 }
60 const onEnd = () => done(false)
61 const onFirstData = () => clearTimeout(peek)
62 // eslint-disable-next-line no-restricted-syntax -- not a sleep: races timeout against stream end/data events
63 const peek = setTimeout(done, ms, true)
64 stream.once('end', onEnd)
65 stream.once('data', onFirstData)
66 })
67}

Callers 1

getInputPromptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected