I hereby claim:
- I am gavrie on github.
- I am gavrie (https://keybase.io/gavrie) on keybase.
- I have a public key whose fingerprint is 6B82 F023 43D1 F603 9023 ADC3 8BA1 C5BF C114 2B70
To claim this, I am signing this object:
#!/usr/bin/env sh | |
## | |
# This is script with usefull tips taken from: | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# | |
# install it: | |
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh | |
# |
I hereby claim:
To claim this, I am signing this object:
# System authorization information | |
auth --enableshadow --passalgo=sha512 | |
# Run the Setup Agent on first boot | |
firstboot --enable | |
# Keyboard layouts | |
keyboard --vckeymap=us --xlayouts='us' | |
# System language | |
lang en_US.UTF-8 |
package retry_test | |
import ( | |
"testing" | |
"time" | |
"github.com/gavrie/retry" | |
) | |
func TestBasic(t *testing.T) { |
package retry | |
import "time" | |
type retrier struct { | |
timeout time.Duration | |
retries int | |
} | |
func New(timeout time.Duration, retries int) *retrier { |
func (er *exponentialRetrier) nextTimeout() time.Duration { | |
er.retries-- | |
t := er.timeout | |
er.timeout *= 2 | |
log.Printf("Next timeout: %v\n", t) | |
return t | |
} |
type retrier interface { | |
nextTimeout() time.Duration | |
keepTrying() bool | |
} |
type basicRetrier struct { | |
// ... | |
virtual retrier | |
} | |
func NewBasic(timeout time.Duration, retries int) *basicRetrier { | |
br := &basicRetrier{ | |
timeout: timeout, | |
retries: retries, | |
} |
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 | |
} |