github.com/volts-dev/volts@v0.0.0-20240120094013-5e9c65924106/internal/backoff/backoff.go (about)

     1  // Package backoff provides backoff functionality
     2  package backoff
     3  
     4  import (
     5  	"math"
     6  	"time"
     7  )
     8  
     9  // Do is a function x^e multiplied by a factor of 0.1 second.
    10  // Result is limited to 2 minute.
    11  func Do(attempts int) time.Duration {
    12  	if attempts > 13 {
    13  		return 2 * time.Minute
    14  	}
    15  	return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100
    16  }