Wrap a function with resilience
Import
withResilience and wrap any function to add retry logic, timeouts, and more:withResilience always returns an async function, even if your original function is synchronous.Call your resilient function
Use the wrapped function just like the original:The function will automatically:
- Retry up to 3 times on failure
- Wait with exponential backoff between retries
- Timeout after 5 seconds
- Log attempt and retry information
What’s happening under the hood?
When you wrap a function withwithResilience:
- First attempt: The function executes normally
- On failure: If the function throws an error and retries are configured, Resilience catches it
- Backoff delay: Waits for the calculated delay (fixed or exponential)
- Retry: Attempts the function again
- Hooks: Triggers lifecycle hooks at each stage for observability
- Circuit breaker: If configured, opens after threshold failures to prevent cascading issues
Common configurations
Simple retry with fixed delay
Exponential backoff with jitter
Circuit breaker for protecting downstream services
Next steps
Installation
Detailed installation and setup instructions
Core concepts
Learn about retries, backoff strategies, and circuit breakers
Configuration
Complete configuration reference
API reference
Full API documentation

