| 48 | } |
| 49 | |
| 50 | async function drain() { |
| 51 | if (running) return |
| 52 | running = true |
| 53 | try { |
| 54 | while (true) { |
| 55 | if (input.paused()) return |
| 56 | if (root) { |
| 57 | root = false |
| 58 | await input.bootstrap() |
| 59 | await tick() |
| 60 | continue |
| 61 | } |
| 62 | const dirs = take(2) |
| 63 | if (dirs.length === 0) return |
| 64 | await Promise.all(dirs.map((dir) => input.bootstrapInstance(dir))) |
| 65 | await tick() |
| 66 | } |
| 67 | } finally { |
| 68 | running = false |
| 69 | // oxlint-disable-next-line no-unsafe-finally -- intentional: early return skips schedule() when paused |
| 70 | if (input.paused()) return |
| 71 | if (root || queued.size) schedule() |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return { |
| 76 | push, |