( files: string[], )
| 462 | * the main thread for >10ms at a time. |
| 463 | */ |
| 464 | export async function getDirectoryNamesAsync( |
| 465 | files: string[], |
| 466 | ): Promise<string[]> { |
| 467 | const directoryNames = new Set<string>() |
| 468 | // Time-based chunking: yield after CHUNK_MS of work so slow machines get |
| 469 | // smaller chunks and stay responsive. |
| 470 | let chunkStart = performance.now() |
| 471 | for (let i = 0; i < files.length; i++) { |
| 472 | collectDirectoryNames(files, i, i + 1, directoryNames) |
| 473 | if ((i & 0xff) === 0xff && performance.now() - chunkStart > CHUNK_MS) { |
| 474 | await yieldToEventLoop() |
| 475 | chunkStart = performance.now() |
| 476 | } |
| 477 | } |
| 478 | return [...directoryNames].map(d => d + path.sep) |
| 479 | } |
| 480 | |
| 481 | function collectDirectoryNames( |
| 482 | files: string[], |
no test coverage detected