| 134 | return new Promise((resolve, reject) => { |
| 135 | const started = Date.now(); |
| 136 | const tick = () => { |
| 137 | let v: T | undefined | null | false; |
| 138 | try { v = predicate(); } catch (e) { return reject(e); } |
| 139 | if (v) return resolve(v as T); |
| 140 | if (Date.now() - started > timeoutMs) { |
| 141 | // Name the wait: an async stack loses the await site, so an unlabeled |
| 142 | // timeout can't tell WHICH step flaked (the #662 test's recurring |
| 143 | // timeout was undiagnosable for exactly this reason). |
| 144 | return reject(new Error(`Timed out after ${timeoutMs}ms${label ? ` waiting for: ${label}` : ''}`)); |
| 145 | } |
| 146 | setTimeout(tick, pollMs); |
| 147 | }; |
| 148 | tick(); |
| 149 | }); |
| 150 | } |