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

Function peekForStdinData

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

Source from the content-addressed store, hash-verified

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

Callers 1

getInputPromptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected