MCPcopy Index your code
hub / github.com/langgenius/dify / waitForOutput

Function waitForOutput

packages/dev-proxy/src/cli.spec.ts:54–90  ·  view source on GitHub ↗
(
  child: DevProxyCliProcess,
  output: () => string,
  expectedOutput: string,
)

Source from the content-addressed store, hash-verified

52}
53
54const waitForOutput = (
55 child: DevProxyCliProcess,
56 output: () => string,
57 expectedOutput: string,
58) => new Promise<void>((resolve, reject) => {
59 let timeout: ReturnType<typeof setTimeout>
60
61 function cleanup() {
62 clearTimeout(timeout)
63 child.stdout.off('data', onData)
64 child.stderr.off('data', onData)
65 child.off('exit', onExit)
66 }
67
68 function onData() {
69 if (!output().includes(expectedOutput))
70 return
71
72 cleanup()
73 resolve()
74 }
75
76 function onExit(code: number | null, signal: NodeJS.Signals | null) {
77 cleanup()
78 reject(new Error(`dev-proxy exited before writing "${expectedOutput}" with code ${code} and signal ${signal}. Output:\n${output()}`))
79 }
80
81 timeout = setTimeout(() => {
82 cleanup()
83 reject(new Error(`Timed out waiting for "${expectedOutput}". Output:\n${output()}`))
84 }, 3000)
85
86 child.stdout.on('data', onData)
87 child.stderr.on('data', onData)
88 child.once('exit', onExit)
89 onData()
90})
91
92const fetchTextWithRetry = async (url: string) => {
93 let lastError: unknown

Callers 1

cli.spec.tsFile · 0.85

Calls 3

onDataFunction · 0.85
cleanupFunction · 0.70
onMethod · 0.45

Tested by

no test coverage detected