github.com/Cloud-Foundations/Dominator@v0.3.4/lib/backoffdelay/api.go (about)

     1  package backoffdelay
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  type Exponential struct {
     8  	growthRate uint
     9  	interval   time.Duration
    10  	maximum    time.Duration
    11  	minimum    time.Duration
    12  	sleepFunc  func(time.Duration)
    13  }
    14  
    15  type Resetter interface {
    16  	Reset()
    17  }
    18  
    19  type Sleeper interface {
    20  	Sleep()
    21  }
    22  
    23  // NewExponential creates a Sleeper with specified minimum and maximum delays.
    24  // If minimumDelay is less than or equal to 0, the default is 1 second.
    25  // If maximumDelay is less than or equal to minimumDelay, the default is 10
    26  // times minimumDelay.
    27  // The Sleep interval will increase by a factor of 2 raised to the power of
    28  // -growthRate. For example:
    29  // 0: 1x
    30  // 1: 0.5x
    31  // 2: 0.25x
    32  func NewExponential(minimumDelay, maximumDelay time.Duration,
    33  	growthRate uint) *Exponential {
    34  	return newExponential(minimumDelay, maximumDelay, growthRate)
    35  }
    36  
    37  func (e *Exponential) Reset() {
    38  	e.reset()
    39  }
    40  
    41  func (e *Exponential) Sleep() {
    42  	e.sleep()
    43  }