| 1391 | // after the drain). storeResult / recordParseFailure run here single-threaded, |
| 1392 | // so shared counters and SQLite writes never race despite parallel parsing. |
| 1393 | const flushOrdered = (): void => { |
| 1394 | if (aborted) return; |
| 1395 | while (completed.has(nextToStore)) { |
| 1396 | const item = completed.get(nextToStore)!; |
| 1397 | completed.delete(nextToStore); |
| 1398 | nextToStore++; |
| 1399 | if (item.ok) storeResult(item.filePath, item.content, item.stats, item.result); |
| 1400 | else recordParseFailure(item.filePath, item.err); |
| 1401 | } |
| 1402 | }; |
| 1403 | |
| 1404 | // Dispatch one file's parse (parses run concurrently across the pool), tagged |
| 1405 | // with its file-order sequence so flushOrdered commits results in order. The |