MCPcopy Index your code
hub / github.com/codeaashu/claude-code / drainRunLoop

Function drainRunLoop

src/utils/computerUse/drainRunLoop.ts:61–79  ·  view source on GitHub ↗
(fn: () => Promise<T>)

Source from the content-addressed store, hash-verified

59 * concurrent drainRunLoop() calls share one setInterval.
60 */
61export async function drainRunLoop<T>(fn: () => Promise<T>): Promise<T> {
62 retain()
63 let timer: ReturnType<typeof setTimeout> | undefined
64 try {
65 // If the timeout wins the race, fn()'s promise is orphaned — a late
66 // rejection from the native layer would become an unhandledRejection.
67 // Attaching a no-op catch swallows it; the timeout error is what surfaces.
68 // fn() sits inside try so a synchronous throw (e.g. NAPI argument
69 // validation) still reaches release() — otherwise the pump leaks.
70 const work = fn()
71 work.catch(() => {})
72 const timeout = withResolvers<never>()
73 timer = setTimeout(timeoutReject, TIMEOUT_MS, timeout.reject)
74 return await Promise.race([work, timeout.promise])
75 } finally {
76 clearTimeout(timer)
77 release()
78 }
79}
80

Callers 9

prepareForActionFunction · 0.85
resolvePrepareCaptureFunction · 0.85
screenshotFunction · 0.85
zoomFunction · 0.85
keyFunction · 0.85
holdKeyFunction · 0.85
typeFunction · 0.85
clickFunction · 0.85
listInstalledAppsFunction · 0.85

Calls 3

retainFunction · 0.85
withResolversFunction · 0.85
releaseFunction · 0.70

Tested by

no test coverage detected