18 lines
		
	
	
		
			404 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			18 lines
		
	
	
		
			404 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package client
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"math"
 | |
| 	"time"
 | |
| )
 | |
| 
 | |
| type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error)
 | |
| 
 | |
| // exponential backoff
 | |
| func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) {
 | |
| 	if attempts == 0 {
 | |
| 		return time.Duration(0), nil
 | |
| 	}
 | |
| 	return time.Duration(math.Pow(10, float64(attempts))) * time.Millisecond, nil
 | |
| }
 |