Fix broken syntax, incorrect parameter types, etc in examples

Pero 2015-04-23 13:27:36 -07:00
parent 653d145763
commit 336019ed2e

@ -8,8 +8,8 @@ For higher rates, prefer a token bucket rate limiter (search godoc.org for
```go ```go
import "time" import "time"
ratePerSec := 10 rate := time.Second / 10
throttle := time.Tick(1e9 / ratePerSec) throttle := time.Tick(rate)
for req := range requests { for req := range requests {
<-throttle // rate limit our Service.Method RPCs <-throttle // rate limit our Service.Method RPCs
go client.Call("Service.Method", req, ...) go client.Call("Service.Method", req, ...)
@ -20,15 +20,15 @@ To allow some bursts, add a buffer to the throttle:
```go ```go
import "time" import "time"
ratePerSec := 10 rate := time.Second / 10
burstLimit := 100 burstLimit := 100
tick := time.NewTicker(1e9 / ratePerSec) tick := time.NewTicker(rate)
defer tick.Stop() defer tick.Stop()
throttle := make(chan time.Time, burstLimit) throttle := make(chan time.Time, burstLimit)
go func() { go func() {
for t := range tick { for t := range tick.C {
select { select {
case: throttle <- t case throttle <- t:
default: default:
} }
} // exits after tick.Stop() } // exits after tick.Stop()