Replaced Tick with NewTicker
This commit is contained in:
parent
58e66a8103
commit
52bb14eb25
@ -4,7 +4,7 @@
|
|||||||
// elegantly supports rate limiting with goroutines,
|
// elegantly supports rate limiting with goroutines,
|
||||||
// channels, and [tickers](tickers).
|
// channels, and [tickers](tickers).
|
||||||
|
|
||||||
package main
|
package examples
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -26,13 +26,13 @@ func main() {
|
|||||||
// This `limiter` channel will receive a value
|
// This `limiter` channel will receive a value
|
||||||
// every 200 milliseconds. This is the regulator in
|
// every 200 milliseconds. This is the regulator in
|
||||||
// our rate limiting scheme.
|
// our rate limiting scheme.
|
||||||
limiter := time.Tick(200 * time.Millisecond)
|
limiter := time.NewTicker(200 * time.Millisecond)
|
||||||
|
|
||||||
// By blocking on a receive from the `limiter` channel
|
// By blocking on a receive from the `limiter` channel
|
||||||
// before serving each request, we limit ourselves to
|
// before serving each request, we limit ourselves to
|
||||||
// 1 request every 200 milliseconds.
|
// 1 request every 200 milliseconds.
|
||||||
for req := range requests {
|
for req := range requests {
|
||||||
<-limiter
|
<-limiter.C
|
||||||
fmt.Println("request", req, time.Now())
|
fmt.Println("request", req, time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user