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

Function createCombinedAbortSignal

src/utils/combinedAbortSignal.ts:15–47  ·  view source on GitHub ↗
(
  signal: AbortSignal | undefined,
  opts?: { signalB?: AbortSignal; timeoutMs?: number },
)

Source from the content-addressed store, hash-verified

13 * so the timer is freed immediately on cleanup.
14 */
15export function createCombinedAbortSignal(
16 signal: AbortSignal | undefined,
17 opts?: { signalB?: AbortSignal; timeoutMs?: number },
18): { signal: AbortSignal; cleanup: () => void } {
19 const { signalB, timeoutMs } = opts ?? {}
20 const combined = createAbortController()
21
22 if (signal?.aborted || signalB?.aborted) {
23 combined.abort()
24 return { signal: combined.signal, cleanup: () => {} }
25 }
26
27 let timer: ReturnType<typeof setTimeout> | undefined
28 const abortCombined = () => {
29 if (timer !== undefined) clearTimeout(timer)
30 combined.abort()
31 }
32
33 if (timeoutMs !== undefined) {
34 timer = setTimeout(abortCombined, timeoutMs)
35 timer.unref?.()
36 }
37 signal?.addEventListener('abort', abortCombined)
38 signalB?.addEventListener('abort', abortCombined)
39
40 const cleanup = () => {
41 if (timer !== undefined) clearTimeout(timer)
42 signal?.removeEventListener('abort', abortCombined)
43 signalB?.removeEventListener('abort', abortCombined)
44 }
45
46 return { signal: combined.signal, cleanup }
47}
48

Callers 7

executeHooksFunction · 0.85
executeHooksOutsideREPLFunction · 0.85
executeFunctionHookFunction · 0.85
execPromptHookFunction · 0.85
execAgentHookFunction · 0.85
execHttpHookFunction · 0.85
canUseToolFunction · 0.85

Calls 1

createAbortControllerFunction · 0.85

Tested by

no test coverage detected