|  | @@ -6,10 +6,12 @@ import (
 | 
	
		
			
				|  |  |  )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  var (
 | 
	
		
			
				|  |  | -	RetryFailed = errors.New("All retry attempts failed.")
 | 
	
		
			
				|  |  | +	errorRetryFailed = errors.New("All retry attempts failed.")
 | 
	
		
			
				|  |  |  )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +// Strategy is a way to retry on a specific function.
 | 
	
		
			
				|  |  |  type Strategy interface {
 | 
	
		
			
				|  |  | +  // On performs a retry on a specific function, until it doesn't return any error.
 | 
	
		
			
				|  |  |  	On(func() error) error
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -17,6 +19,7 @@ type retryer struct {
 | 
	
		
			
				|  |  |  	NextDelay func(int) int
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +// On implements Strategy.On.
 | 
	
		
			
				|  |  |  func (r *retryer) On(method func() error) error {
 | 
	
		
			
				|  |  |  	attempt := 0
 | 
	
		
			
				|  |  |  	for {
 | 
	
	
		
			
				|  | @@ -26,13 +29,14 @@ func (r *retryer) On(method func() error) error {
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		delay := r.NextDelay(attempt)
 | 
	
		
			
				|  |  |  		if delay < 0 {
 | 
	
		
			
				|  |  | -			return RetryFailed
 | 
	
		
			
				|  |  | +			return errorRetryFailed
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  		<-time.After(time.Duration(delay) * time.Millisecond)
 | 
	
		
			
				|  |  |  		attempt++
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +// Timed returns a retry strategy with fixed interval.
 | 
	
		
			
				|  |  |  func Timed(attempts int, delay int) Strategy {
 | 
	
		
			
				|  |  |  	return &retryer{
 | 
	
		
			
				|  |  |  		NextDelay: func(attempt int) int {
 |