gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/client/backoff.go (about)

     1  package client
     2  
     3  import (
     4  	"context"
     5  	"math"
     6  	"time"
     7  )
     8  
     9  type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error)
    10  
    11  // exponential backoff
    12  func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) {
    13  	if attempts == 0 {
    14  		return time.Duration(0), nil
    15  	}
    16  	return time.Duration(math.Pow(10, float64(attempts))) * time.Millisecond, nil
    17  }