( predicate: () => boolean, timeoutMs = 1000, )
| 94 | } |
| 95 | |
| 96 | async function waitUntil( |
| 97 | predicate: () => boolean, |
| 98 | timeoutMs = 1000, |
| 99 | ): Promise<void> { |
| 100 | const deadline = Date.now() + timeoutMs |
| 101 | while (Date.now() < deadline) { |
| 102 | if (predicate()) { |
| 103 | return |
| 104 | } |
| 105 | await new Promise(resolve => setTimeout(resolve, 10)) |
| 106 | } |
| 107 | throw new Error('Timed out waiting for background Grove refresh') |
| 108 | } |
| 109 | |
| 110 | function seedManagedConsumerSession(): void { |
| 111 | saveOAuthTokensIfNeeded({ |