Remove `dir` once nothing holds it: Windows can keep it busy a moment after a child exits.
(dir: string, timeoutMs = 5_000)
| 60 | |
| 61 | /** Remove `dir` once nothing holds it: Windows can keep it busy a moment after a child exits. */ |
| 62 | async function removeWhenReleased(dir: string, timeoutMs = 5_000): Promise<void> { |
| 63 | const deadline = Date.now() + timeoutMs; |
| 64 | for (;;) { |
| 65 | try { |
| 66 | fs.rmSync(dir, { recursive: true, force: true }); |
| 67 | return; |
| 68 | } catch (error) { |
| 69 | const code = (error as NodeJS.ErrnoException).code ?? ''; |
| 70 | if (!['EBUSY', 'ENOTEMPTY', 'EPERM'].includes(code) || Date.now() > deadline) throw error; |
| 71 | await delay(50); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | function answered(c: Child, id: number): boolean { |
| 77 | return c.out().split('\n').some((l) => { |
no test coverage detected