Skip to content

Commit

Permalink
update retry
Browse files Browse the repository at this point in the history
  • Loading branch information
da440dil committed Aug 9, 2019
1 parent 5c208ac commit be222b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions examples/counter-with-retry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ func main() {
panic(err)
}
// Create retriable function
fn := func(n int) func() (bool, error) {
return func() (bool, error) {
fn := func(n int) func() (bool, time.Duration, error) {
return func() (bool, time.Duration, error) {
v, err := c.Count("key")
if err == nil {
fmt.Printf("Counter #%v has counted the key, remainder %v\n", n, v)
return true, nil // Success
return true, -1, nil // Success
}
if e, ok := err.(counter.TTLError); ok {
fmt.Printf("Counter #%v has reached the limit, retry after %v\n", n, e.TTL())
return false, nil // Failure
return false, e.TTL(), nil // Failure
}
return false, err // Error
return false, -1, err // Error
}
}
for i := 1; i < 4; i++ {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/da440dil/go-counter
go 1.12

require (
github.com/da440dil/go-trier v0.0.0
github.com/da440dil/go-trier v0.0.1
github.com/go-redis/redis v6.15.2+incompatible
github.com/golang/protobuf v1.3.2 // indirect
github.com/kr/pretty v0.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/da440dil/go-trier v0.0.0 h1:cxPHRwg2dKE/ldqPiLGtgql8VUTfvYlI+eF14BY4+I8=
github.com/da440dil/go-trier v0.0.0/go.mod h1:Xc70OohXdJvxPLfUDjJG3TeOiitY7K4jx+Q0tm5dIy0=
github.com/da440dil/go-trier v0.0.1 h1:plGC/S++x1ZlNjqI+uv8t/32P3TrNY6ddd57cIaxHdU=
github.com/da440dil/go-trier v0.0.1/go.mod h1:Xc70OohXdJvxPLfUDjJG3TeOiitY7K4jx+Q0tm5dIy0=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down

0 comments on commit be222b5

Please sign in to comment.