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

Function useSwarmPermissionPoller

src/hooks/useSwarmPermissionPoller.ts:268–330  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

266 * 4. Cleans up the response file after processing
267 */
268export function useSwarmPermissionPoller(): void {
269 const isProcessingRef = useRef(false)
270
271 const poll = useCallback(async () => {
272 // Don't poll if not a swarm worker
273 if (!isSwarmWorker()) {
274 return
275 }
276
277 // Prevent concurrent polling
278 if (isProcessingRef.current) {
279 return
280 }
281
282 // Don't poll if no callbacks are registered
283 if (pendingCallbacks.size === 0) {
284 return
285 }
286
287 isProcessingRef.current = true
288
289 try {
290 const agentName = getAgentName()
291 const teamName = getTeamName()
292
293 if (!agentName || !teamName) {
294 return
295 }
296
297 // Check each pending request for a response
298 for (const [requestId, _callback] of pendingCallbacks) {
299 const response = await pollForResponse(requestId, agentName, teamName)
300
301 if (response) {
302 // Process the response
303 const processed = processResponse(response)
304
305 if (processed) {
306 // Clean up the response from the worker's inbox
307 await removeWorkerResponse(requestId, agentName, teamName)
308 }
309 }
310 }
311 } catch (error) {
312 logForDebugging(
313 `[SwarmPermissionPoller] Error during poll: ${errorMessage(error)}`,
314 )
315 } finally {
316 isProcessingRef.current = false
317 }
318 }, [])
319
320 // Only poll if we're a swarm worker
321 const shouldPoll = isSwarmWorker()
322 useInterval(() => void poll(), shouldPoll ? POLL_INTERVAL_MS : null)
323
324 // Initial poll on mount
325 useEffect(() => {

Callers

nothing calls this directly

Calls 10

isSwarmWorkerFunction · 0.85
getAgentNameFunction · 0.85
getTeamNameFunction · 0.85
pollForResponseFunction · 0.85
processResponseFunction · 0.85
removeWorkerResponseFunction · 0.85
logForDebuggingFunction · 0.85
useIntervalFunction · 0.85
pollFunction · 0.70
errorMessageFunction · 0.50

Tested by

no test coverage detected