(action: () => T | Promise<T>, checkEveryMilliseconds = 50, tryForMilliseconds = 15000, token?: { isCancellationRequested: boolean })
| 1 | export const resolvedPromise = Promise.resolve(); |
| 2 | |
| 3 | export async function waitFor<T>(action: () => T | Promise<T>, checkEveryMilliseconds = 50, tryForMilliseconds = 15000, token?: { isCancellationRequested: boolean }): Promise<T | undefined> { |
| 4 | let timeRemaining = tryForMilliseconds; |
| 5 | while (timeRemaining > 0 && !(token?.isCancellationRequested)) { |
| 6 | try { |
| 7 | const res = await action(); |
| 8 | if (res) |
| 9 | return res; |
| 10 | } catch { |
| 11 | // Just try again if it throws. |
| 12 | } |
| 13 | await new Promise((resolve) => setTimeout(resolve, checkEveryMilliseconds).unref()); |
| 14 | timeRemaining -= checkEveryMilliseconds; |
| 15 | } |
| 16 | } |
no outgoing calls
no test coverage detected