Timer Types
Infinitic provides two types of timers:Duration Timers
Wait for a relative duration (e.g., 30 seconds, 5 minutes)
Instant Timers
Wait until a specific point in time
Duration Timers
Create a timer that completes after a specified duration:Duration Examples
Instant Timers
Create a timer that completes at a specific point in time:Timer with Deferred
Timers return aDeferred<Instant> that can be used with other deferred operations:
Racing Timers with Other Operations
Useor() to implement timeouts by racing a timer against other operations:
Timeout for Service Calls
Timeout for Channel Signals
Timeout for Sub-workflows
Multiple Timers
Sequential Delays
Parallel Timers
Racing Multiple Timers
Periodic Execution
Implement periodic tasks using timers and recursion:Scheduled Workflows
Schedule workflow execution for specific times:Manual Timer Completion
Timers can be manually completed from outside the workflow (useful for testing or administrative control):Timer Precision
Timer ResolutionTimer precision depends on your configuration:
- Default tick duration is typically 1 second
- Short timers (< 1 second) may complete sooner than expected
- Long timers are more precise as the overhead becomes negligible
Complete Example: Order with Timeout and Retry
Best Practices
Always use timers for delays
Always use timers for delays
Never use
Thread.sleep() or similar blocking operations:Add timeouts to external operations
Add timeouts to external operations
Always add timeouts when waiting for external events:
Use appropriate timeout durations
Use appropriate timeout durations
Choose timeout durations based on expected operation time:
Handle timeout results explicitly
Handle timeout results explicitly
Always check what completed when using
or():Common Patterns
Retry with Exponential Backoff
Polling with Timeout
Rate Limiting
Next Steps
Channels
Learn about receiving external signals
Sub-workflows
Compose workflows from other workflows
Versioning
Update workflows while maintaining compatibility
Workflow Methods
Complete workflow method reference