Schedule module provides utilities for creating and composing schedules that control retry logic, repetition patterns, and various timing strategies.
Overview
ASchedule<Output, Input, Error, Env> is a function that:
- Takes an input and returns a decision whether to continue or halt
- Provides a delay duration before the next attempt
- Can be combined, transformed, and composed with other schedules
- Works seamlessly with Effect.retry and Effect.repeat
Creating Schedules
Basic Schedules
Time-Based Schedules
Using Schedules
With Effect.retry
With Effect.repeat
Composing Schedules
Intersection (Both)
Continues while both schedules want to continue:Union (Either)
Continues while either schedule wants to continue:Compose (Sequential)
Runs first schedule, then second schedule:Transforming Schedules
Map Output
Add Delay
While/Until Conditions
Common Patterns
Exponential Backoff with Cap
Retry with Jitter
Conditional Retry
Polling Pattern
Schedule Metadata
Advanced Schedules
Custom Schedule
Time-of-Day Schedule
Circuit Breaker Pattern
Monitoring Schedules
Tap on Each Iteration
Log on Completion
Best Practices
- Combine schedules: Use intersect/union to create sophisticated retry logic
- Add jitter: Use jittered to prevent thundering herd problems
- Cap maximum delays: Prevent infinite backoff with maximum delay limits
- Limit retry attempts: Always set a maximum number of retries
- Use conditional retries: Only retry on recoverable errors
- Monitor schedule execution: Log attempts and delays for debugging