resilience
Timeout Wrapper
Race an operation against a deadline — fail fast instead of waiting forever
StatusIDLE
Timeout2000ms
Elapsed0.0s
Runs0
Successes0
Timeouts0
Errors0
Promise.race Visualization
⏱ timeout
2000ms deadline
● task
~1500ms expected
// configuration
PRESETS:
// event log
No events yet. Click "Execute Task" to begin.
// how it works
- Wrap an async operation with a maximum deadline.
- Use
Promise.race([action(), timeoutPromise])to race them. - If the action resolves first → return its result.
- If the timeout fires first → throw a
TimeoutError. - Always clean up the timer with
clearTimeoutin afinallyblock.
// trade-offs
- Prevents indefinite waits on hung services
- Frees up resources quickly when services are slow
- Pairs well with retries and circuit breakers
- Does not cancel the underlying operation (JS limitation)
- Too-tight timeouts cause false failures on legitimate slow responses
- Need to choose timeout values carefully per endpoint
// real-world usage
- HTTP client timeouts (e.g., Axios, fetch with AbortController)
- Database query timeouts
- Microservice-to-microservice RPC calls
- Composition:
timeout → retry → circuit-breaker