Skip to content

Instantly share code, notes, and snippets.

@gavrie
Last active May 17, 2016 13:13
Show Gist options
  • Save gavrie/529fbeeabd2cd7b83c1aac07d6f47e63 to your computer and use it in GitHub Desktop.
Save gavrie/529fbeeabd2cd7b83c1aac07d6f47e63 to your computer and use it in GitHub Desktop.

Revisions

  1. gavrie revised this gist May 17, 2016. 1 changed file with 1 addition and 12 deletions.
    13 changes: 1 addition & 12 deletions retry_virtual.go
    Original file line number Diff line number Diff line change
    @@ -10,15 +10,4 @@ func NewBasic(timeout time.Duration, retries int) *basicRetrier {
    }
    br.virtual = br
    return br
    }

    func (br *basicRetrier) TotalTimeout() (total time.Duration) {
    r := *br // Make a copy to preserve unchanged original

    for r.virtual.keepTrying() {
    total += r.virtual.nextTimeout()
    }

    log.Printf("Total timeout: %v\n", total)
    return total
    }
    }
  2. gavrie revised this gist May 17, 2016. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion retry_virtual.go
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,10 @@ type basicRetrier struct {
    }

    func NewBasic(timeout time.Duration, retries int) *basicRetrier {
    // ...
    br := &basicRetrier{
    timeout: timeout,
    retries: retries,
    }
    br.virtual = br
    return br
    }
  3. gavrie created this gist May 17, 2016.
    21 changes: 21 additions & 0 deletions retry_virtual.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    type basicRetrier struct {
    // ...
    virtual retrier
    }

    func NewBasic(timeout time.Duration, retries int) *basicRetrier {
    // ...
    br.virtual = br
    return br
    }

    func (br *basicRetrier) TotalTimeout() (total time.Duration) {
    r := *br // Make a copy to preserve unchanged original

    for r.virtual.keepTrying() {
    total += r.virtual.nextTimeout()
    }

    log.Printf("Total timeout: %v\n", total)
    return total
    }