Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
da440dil committed Aug 7, 2019
1 parent 1752718 commit 47cb721
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func main() {
}
key := "key"
var wg sync.WaitGroup
count := func() {
count := func(n int) {
wg.Add(1)
go func() {
v, err := c.Count(key)
if err == nil {
fmt.Printf("Counter has counted the key, remainder %v\n", v)
fmt.Printf("Counter #%v has counted the key, remainder %v\n", n, v)
} else {
if e, ok := err.(counter.TTLError); ok {
fmt.Printf("Counter has reached the limit, retry after %v\n", e.TTL())
fmt.Printf("Counter #%v has reached the limit, retry after %v\n", n, e.TTL())
} else {
panic(err)
}
Expand All @@ -44,9 +44,9 @@ func main() {
}()
}

count() // Counter has counted the key, remainder 1
count() // Counter has counted the key, remainder 0
count() // Counter has reached the limit, retry after 100ms
count(1) // Counter #1 has counted the key, remainder 1
count(2) // Counter #2 has counted the key, remainder 0
count(3) // Counter #3 has reached the limit, retry after 100ms
wg.Wait()
}
```
36 changes: 18 additions & 18 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ func ExampleCounter_withoutGateway() {
}
key := "key"
var wg sync.WaitGroup
count := func() {
count := func(n int) {
wg.Add(1)
go func() {
v, err := c.Count(key)
if err == nil {
fmt.Printf("Counter has counted the key, remainder %v\n", v)
fmt.Printf("Counter #%v has counted the key, remainder %v\n", n, v)
} else {
if e, ok := err.(counter.TTLError); ok {
fmt.Printf("Counter has reached the limit, retry after %v\n", e.TTL())
fmt.Printf("Counter #%v has reached the limit, retry after %v\n", n, e.TTL())
} else {
panic(err)
}
Expand All @@ -35,9 +35,9 @@ func ExampleCounter_withoutGateway() {
}()
}

count() // Counter has counted the key, remainder 1
count() // Counter has counted the key, remainder 0
count() // Counter has reached the limit, retry after 100ms
count(1) // Counter #1 has counted the key, remainder 1
count(2) // Counter #2 has counted the key, remainder 0
count(3) // Counter #3 has reached the limit, retry after 100ms
wg.Wait()
}

Expand All @@ -49,15 +49,15 @@ func ExampleCounter_memoryGateway() {
}
key := "key"
var wg sync.WaitGroup
count := func() {
count := func(n int) {
wg.Add(1)
go func() {
v, err := c.Count(key)
if err == nil {
fmt.Printf("Counter has counted the key, remainder %v\n", v)
fmt.Printf("Counter #%v has counted the key, remainder %v\n", n, v)
} else {
if e, ok := err.(counter.TTLError); ok {
fmt.Printf("Counter has reached the limit, retry after %v\n", e.TTL())
fmt.Printf("Counter #%v has reached the limit, retry after %v\n", n, e.TTL())
} else {
panic(err)
}
Expand All @@ -66,9 +66,9 @@ func ExampleCounter_memoryGateway() {
}()
}

count() // Counter has counted the key, remainder 1
count() // Counter has counted the key, remainder 0
count() // Counter has reached the limit, retry after 100ms
count(1) // Counter #1 has counted the key, remainder 1
count(2) // Counter #2 has counted the key, remainder 0
count(3) // Counter #3 has reached the limit, retry after 100ms
wg.Wait()
}

Expand All @@ -83,15 +83,15 @@ func ExampleCounter_redisGateway() {
}
key := "key"
var wg sync.WaitGroup
count := func() {
count := func(n int) {
wg.Add(1)
go func() {
v, err := c.Count(key)
if err == nil {
fmt.Printf("Counter has counted the key, remainder %v\n", v)
fmt.Printf("Counter #%v has counted the key, remainder %v\n", n, v)
} else {
if e, ok := err.(counter.TTLError); ok {
fmt.Printf("Counter has reached the limit, retry after %v\n", e.TTL())
fmt.Printf("Counter #%v has reached the limit, retry after %v\n", n, e.TTL())
} else {
panic(err)
}
Expand All @@ -100,8 +100,8 @@ func ExampleCounter_redisGateway() {
}()
}

count() // Counter has counted the key, remainder 1
count() // Counter has counted the key, remainder 0
count() // Counter has reached the limit, retry after 100ms
count(1) // Counter #1 has counted the key, remainder 1
count(2) // Counter #2 has counted the key, remainder 0
count(3) // Counter #3 has reached the limit, retry after 100ms
wg.Wait()
}

0 comments on commit 47cb721

Please sign in to comment.