summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/goamz/goamz/aws/attempt.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/goamz/goamz/aws/attempt.go')
-rw-r--r--vendor/github.com/goamz/goamz/aws/attempt.go74
1 files changed, 0 insertions, 74 deletions
diff --git a/vendor/github.com/goamz/goamz/aws/attempt.go b/vendor/github.com/goamz/goamz/aws/attempt.go
deleted file mode 100644
index c0654f5d8..000000000
--- a/vendor/github.com/goamz/goamz/aws/attempt.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package aws
-
-import (
- "time"
-)
-
-// AttemptStrategy represents a strategy for waiting for an action
-// to complete successfully. This is an internal type used by the
-// implementation of other goamz packages.
-type AttemptStrategy struct {
- Total time.Duration // total duration of attempt.
- Delay time.Duration // interval between each try in the burst.
- Min int // minimum number of retries; overrides Total
-}
-
-type Attempt struct {
- strategy AttemptStrategy
- last time.Time
- end time.Time
- force bool
- count int
-}
-
-// Start begins a new sequence of attempts for the given strategy.
-func (s AttemptStrategy) Start() *Attempt {
- now := time.Now()
- return &Attempt{
- strategy: s,
- last: now,
- end: now.Add(s.Total),
- force: true,
- }
-}
-
-// Next waits until it is time to perform the next attempt or returns
-// false if it is time to stop trying.
-func (a *Attempt) Next() bool {
- now := time.Now()
- sleep := a.nextSleep(now)
- if !a.force && !now.Add(sleep).Before(a.end) && a.strategy.Min <= a.count {
- return false
- }
- a.force = false
- if sleep > 0 && a.count > 0 {
- time.Sleep(sleep)
- now = time.Now()
- }
- a.count++
- a.last = now
- return true
-}
-
-func (a *Attempt) nextSleep(now time.Time) time.Duration {
- sleep := a.strategy.Delay - now.Sub(a.last)
- if sleep < 0 {
- return 0
- }
- return sleep
-}
-
-// HasNext returns whether another attempt will be made if the current
-// one fails. If it returns true, the following call to Next is
-// guaranteed to return true.
-func (a *Attempt) HasNext() bool {
- if a.force || a.strategy.Min > a.count {
- return true
- }
- now := time.Now()
- if now.Add(a.nextSleep(now)).Before(a.end) {
- a.force = true
- return true
- }
- return false
-}