( files: string[], )
| 401 | * the main thread for >10ms at a time. |
| 402 | */ |
| 403 | export async function getDirectoryNamesAsync( |
| 404 | files: string[], |
| 405 | ): Promise<string[]> { |
| 406 | const directoryNames = new Set<string>() |
| 407 | // Time-based chunking: yield after CHUNK_MS of work so slow machines get |
| 408 | // smaller chunks and stay responsive. |
| 409 | let chunkStart = performance.now() |
| 410 | for (let i = 0; i < files.length; i++) { |
| 411 | collectDirectoryNames(files, i, i + 1, directoryNames) |
| 412 | if ((i & 0xff) === 0xff && performance.now() - chunkStart > CHUNK_MS) { |
| 413 | await yieldToEventLoop() |
| 414 | chunkStart = performance.now() |
| 415 | } |
| 416 | } |
| 417 | return [...directoryNames].map(d => d + path.sep) |
| 418 | } |
| 419 | |
| 420 | function collectDirectoryNames( |
| 421 | files: string[], |
no test coverage detected