mediumCodingMidSenior
Write a helper that polls a condition until it is true or a timeout expires, then tell me what yours does when the condition throws.
4 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup
Answer
Short answer
A correct wait helper tracks a wall-clock deadline rather than an attempt count, treats an exception from the condition as a not-yet rather than a failure, returns the condition's value, and reports the last observed value or error when it gives up.
Was this answer helpful?
Likely follow-ups
- How would you make this cancellable so shutting a suite down does not wait out every remaining timeout?
- The condition costs a database query each time. What changes about the polling strategy?
- How would you test this helper without making the test take thirty seconds?
- Where is polling the wrong tool entirely, and what replaces it?
Related questions
- A promise rejects and nothing is awaiting it. What does Node do?hardAlso on async4 min
- You kick off background work from a controller action and it throws once the response has gone out. What is happening?mediumAlso on async5 min
- A client disconnects but your server keeps working on their request. How does cancellation actually propagate in .NET?mediumAlso on async4 min
- Given an access log, write a utility that reports request count, error rate and p95 latency per endpoint.mediumAlso on sdet5 min