MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / drainRunLoop

Function drainRunLoop

source code/utils/computerUse/drainRunLoop.ts:63–81  ·  view source on GitHub ↗
(fn: () => Promise<T>)

Source from the content-addressed store, hash-verified

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

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