summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/nlopes/slack/backoff.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-09-07 22:46:58 +0200
committerGitHub <noreply@github.com>2019-09-07 22:46:58 +0200
commita3bee01e0af3394c19360b98fd2db1b647f49299 (patch)
treeffc5778361d55d592a718354a37c9251e75fc7f6 /vendor/github.com/nlopes/slack/backoff.go
parent1dc93ec4f001edd01daccbe408767d4878be25a3 (diff)
downloadmatterbridge-msglm-a3bee01e0af3394c19360b98fd2db1b647f49299.tar.gz
matterbridge-msglm-a3bee01e0af3394c19360b98fd2db1b647f49299.tar.bz2
matterbridge-msglm-a3bee01e0af3394c19360b98fd2db1b647f49299.zip
Update dependencies (#886)
Diffstat (limited to 'vendor/github.com/nlopes/slack/backoff.go')
-rw-r--r--vendor/github.com/nlopes/slack/backoff.go50
1 files changed, 25 insertions, 25 deletions
diff --git a/vendor/github.com/nlopes/slack/backoff.go b/vendor/github.com/nlopes/slack/backoff.go
index 197bce2e..2ba697e7 100644
--- a/vendor/github.com/nlopes/slack/backoff.go
+++ b/vendor/github.com/nlopes/slack/backoff.go
@@ -1,7 +1,6 @@
package slack
import (
- "math"
"math/rand"
"time"
)
@@ -14,41 +13,42 @@ import (
// conjunction with the time package.
type backoff struct {
attempts int
- //Factor is the multiplying factor for each increment step
- Factor float64
- //Jitter eases contention by randomizing backoff steps
- Jitter bool
- //Min and Max are the minimum and maximum values of the counter
- Min, Max time.Duration
+ // Initial value to scale out
+ Initial time.Duration
+ // Jitter value randomizes an additional delay between 0 and Jitter
+ Jitter time.Duration
+ // Max maximum values of the backoff
+ Max time.Duration
}
// Returns the current value of the counter and then multiplies it
// Factor
-func (b *backoff) Duration() time.Duration {
- //Zero-values are nonsensical, so we use
- //them to apply defaults
- if b.Min == 0 {
- b.Min = 100 * time.Millisecond
- }
+func (b *backoff) Duration() (dur time.Duration) {
+ // Zero-values are nonsensical, so we use
+ // them to apply defaults
if b.Max == 0 {
b.Max = 10 * time.Second
}
- if b.Factor == 0 {
- b.Factor = 2
+
+ if b.Initial == 0 {
+ b.Initial = 100 * time.Millisecond
}
- //calculate this duration
- dur := float64(b.Min) * math.Pow(b.Factor, float64(b.attempts))
- if b.Jitter {
- dur = rand.Float64()*(dur-float64(b.Min)) + float64(b.Min)
+
+ // calculate this duration
+ if dur = time.Duration(1 << uint(b.attempts)); dur > 0 {
+ dur = dur * b.Initial
+ } else {
+ dur = b.Max
}
- //cap!
- if dur > float64(b.Max) {
- return b.Max
+
+ if b.Jitter > 0 {
+ dur = dur + time.Duration(rand.Intn(int(b.Jitter)))
}
- //bump attempts count
+
+ // bump attempts count
b.attempts++
- //return as a time.Duration
- return time.Duration(dur)
+
+ return dur
}
//Resets the current value of the counter back to Min