( predicate: () => T | undefined | null | false, timeoutMs: number, pollMs = 25, )
| 117 | } |
| 118 | |
| 119 | function waitFor<T>( |
| 120 | predicate: () => T | undefined | null | false, |
| 121 | timeoutMs: number, |
| 122 | pollMs = 25, |
| 123 | ): Promise<T> { |
| 124 | return new Promise((resolve, reject) => { |
| 125 | const started = Date.now(); |
| 126 | const tick = () => { |
| 127 | let v: T | undefined | null | false; |
| 128 | try { v = predicate(); } catch (e) { return reject(e); } |
| 129 | if (v) return resolve(v as T); |
| 130 | if (Date.now() - started > timeoutMs) return reject(new Error(`Timed out after ${timeoutMs}ms`)); |
| 131 | setTimeout(tick, pollMs); |
| 132 | }; |
| 133 | tick(); |
| 134 | }); |
| 135 | } |
| 136 | |
| 137 | function isAlive(pid: number): boolean { |
| 138 | try { process.kill(pid, 0); return true; } catch { return false; } |
no test coverage detected