Mode entretien. Minuteur de 8 min, sans indices ni autocomplétion
Wait for a condition
FacileAsync code8 min
Write a function waitFor(cond, interval, timeout) that returns a promise. Call cond() at once and then every interval milliseconds.
As soon as cond() returns true, the promise resolves. If timeout milliseconds have passed and the condition is still false, the promise rejects with new Error('Timeout'). In both cases the checks stop.
Exemples
await waitFor(() => true, 50, 500)Renvoie undefined
await waitFor(() => false, 50, 200).catch((e) => e.message)Renvoie 'Timeout'
Chargement de l'éditeur...
- The condition is true at once, no need to wait for interval
- The condition becomes true after 120 ms
- The condition is not met within 200 ms
Les tests cachés se lancent à la soumission