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

Function drainRunLoop

src/utils/computerUse/drainRunLoop.ts:61–80  ·  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 if (process.platform !== 'darwin') return fn()
63 retain()
64 let timer: ReturnType<typeof setTimeout> | undefined
65 try {
66 // If the timeout wins the race, fn()'s promise is orphaned — a late
67 // rejection from the native layer would become an unhandledRejection.
68 // Attaching a no-op catch swallows it; the timeout error is what surfaces.
69 // fn() sits inside try so a synchronous throw (e.g. NAPI argument
70 // validation) still reaches release() — otherwise the pump leaks.
71 const work = fn()
72 work.catch(() => {})
73 const timeout = withResolvers<never>()
74 timer = setTimeout(timeoutReject, TIMEOUT_MS, timeout.reject)
75 return await Promise.race([work, timeout.promise])
76 } finally {
77 clearTimeout(timer)
78 release()
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