MCPcopy Create free account
hub / github.com/electric-sql/electric / execFileWithTimeout

Function execFileWithTimeout

packages/agents-desktop/src/cli/controller.ts:279–325  ·  view source on GitHub ↗
(
  file: string,
  args: string[],
  timeoutMs: number,
  env: NodeJS.ProcessEnv = process.env
)

Source from the content-addressed store, hash-verified

277}
278
279function execFileWithTimeout(
280 file: string,
281 args: string[],
282 timeoutMs: number,
283 env: NodeJS.ProcessEnv = process.env
284): Promise<{ stdout: string; error: Error | null }> {
285 return new Promise((resolve) => {
286 const child = spawn(file, args, {
287 env,
288 stdio: [`ignore`, `pipe`, `pipe`],
289 })
290 let stdout = ``
291 let stderr = ``
292 const timeout = setTimeout(() => {
293 child.kill()
294 resolve({
295 stdout,
296 error: new Error(`Timed out while checking Electric CLI version.`),
297 })
298 }, timeoutMs)
299 child.stdout?.setEncoding(`utf8`)
300 child.stderr?.setEncoding(`utf8`)
301 child.stdout?.on(`data`, (chunk: string) => {
302 stdout += chunk
303 })
304 child.stderr?.on(`data`, (chunk: string) => {
305 stderr += chunk
306 })
307 child.on(`error`, (error) => {
308 clearTimeout(timeout)
309 resolve({ stdout, error })
310 })
311 child.on(`close`, (code) => {
312 clearTimeout(timeout)
313 if (code === 0) {
314 resolve({ stdout, error: null })
315 return
316 }
317 resolve({
318 stdout,
319 error: new Error(
320 stderr.trim() || `Electric CLI exited with code ${code}.`
321 ),
322 })
323 })
324 })
325}

Callers 2

readBundledCliVersionFunction · 0.85
readCliVersionResultFunction · 0.85

Calls 5

setTimeoutFunction · 0.85
resolveFunction · 0.85
killMethod · 0.65
spawnFunction · 0.50
onMethod · 0.45

Tested by

no test coverage detected