( predicate: () => boolean, timeoutMs = 3000, )
| 128 | } |
| 129 | |
| 130 | async function waitUntil( |
| 131 | predicate: () => boolean, |
| 132 | timeoutMs = 3000, |
| 133 | ): Promise<void> { |
| 134 | const deadline = Date.now() + timeoutMs |
| 135 | while (Date.now() < deadline) { |
| 136 | if (predicate()) { |
| 137 | return |
| 138 | } |
| 139 | await new Promise(resolve => setTimeout(resolve, 10)) |
| 140 | } |
| 141 | throw new Error('Timed out waiting for background referral refresh') |
| 142 | } |
| 143 | |
| 144 | function makeEligibility(eligible: boolean, remainingPasses: number) { |
| 145 | return { |