()
| 65 | const readIndexes = useCallback(async () => { |
| 66 | if (inFlight.current) return inFlight.current; |
| 67 | const read = async () => { |
| 68 | if (!listProjects) throw new Error('Project inventory is unavailable.'); |
| 69 | const projects = await listProjects(); |
| 70 | const rows = new Array<IndexReading>(projects.length); |
| 71 | let cursor = 0; |
| 72 | const worker = async () => { |
| 73 | while (cursor < projects.length) { |
| 74 | if (!enabled.current || document.visibilityState === 'hidden') throw new Error('Index reading paused.'); |
| 75 | const index = cursor++; |
| 76 | const project = projects[index]; |
| 77 | try { |
| 78 | if (!api.projectHealth) throw new Error('Project health is unavailable.'); |
| 79 | rows[index] = { project, health: await api.projectHealth(project.name), error: null }; |
| 80 | } catch (error) { |
| 81 | rows[index] = { project, health: previous.current.get(project.name)?.health ?? null, error: failureText(error) }; |
| 82 | } |
| 83 | } |
| 84 | }; |
| 85 | const work = await Promise.allSettled(Array.from({ length: Math.min(4, projects.length) }, worker)); |
| 86 | const failed = work.find(result => result.status === 'rejected'); |
| 87 | if (failed?.status === 'rejected') throw failed.reason; |
| 88 | previous.current = new Map(rows.map(row => [row.project.name, row])); |
| 89 | return rows; |
| 90 | }; |
| 91 | const request = read(); |
| 92 | inFlight.current = request; |
| 93 | try { return await request; } |
no outgoing calls
no test coverage detected