20 lines
452 B
Go
20 lines
452 B
Go
package backgroundtask
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// WithInterval sets the interval between periodic work executions.
|
|
// The interval must be between MinInterval and MaxInterval.
|
|
func WithInterval(d time.Duration) Option {
|
|
return func(r *Runner) error {
|
|
if d < MinInterval || d > MaxInterval {
|
|
return fmt.Errorf("%w: got %v, must be between %v and %v",
|
|
ErrInvalidInterval, d, MinInterval, MaxInterval)
|
|
}
|
|
r.interval = d
|
|
return nil
|
|
}
|
|
}
|