(callback: () => boolean | void, { interval, timeout }: WaitOptions)
| 15 | |
| 16 | function asyncUtils(act: Act, addResolver: (callback: () => void) => void): AsyncUtils { |
| 17 | const wait = async (callback: () => boolean | void, { interval, timeout }: WaitOptions) => { |
| 18 | const checkResult = () => { |
| 19 | const callbackResult = callback() |
| 20 | return callbackResult ?? callbackResult === undefined |
| 21 | } |
| 22 | |
| 23 | const timeoutSignal = createTimeoutController(timeout) |
| 24 | |
| 25 | const waitForResult = async () => { |
| 26 | while (true) { |
| 27 | const intervalSignal = createTimeoutController(interval) |
| 28 | timeoutSignal.onTimeout(() => intervalSignal.cancel()) |
| 29 | |
| 30 | await intervalSignal.wrap(new Promise<void>(addResolver)) |
| 31 | |
| 32 | if (checkResult() || timeoutSignal.timedOut) { |
| 33 | return |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | if (!checkResult()) { |
| 39 | await act(() => timeoutSignal.wrap(waitForResult())) |
| 40 | } |
| 41 | |
| 42 | return !timeoutSignal.timedOut |
| 43 | } |
| 44 | |
| 45 | const waitFor = async ( |
| 46 | callback: () => boolean | void, |
no test coverage detected
searching dependent graphs…