()
| 14 | return Promise.race([ |
| 15 | new Promise<void>((resolve) => { |
| 16 | const check = async () => { |
| 17 | const result = condition() |
| 18 | const isSatisfied = result instanceof Promise ? await result : result |
| 19 | |
| 20 | if (isSatisfied) { |
| 21 | if (timeoutId) { |
| 22 | clearTimeout(timeoutId) |
| 23 | timeoutId = undefined |
| 24 | } |
| 25 | |
| 26 | resolve() |
| 27 | } else { |
| 28 | setTimeout(check, interval) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | check() |
| 33 | }), |