Use more idiomatic <int> * <const> for intervals

This commit is contained in:
Mark McGranaghan
2018-02-09 14:14:25 -08:00
parent 1d272218fd
commit 01a5f6de68
15 changed files with 37 additions and 37 deletions

View File

@@ -24,7 +24,7 @@ func main() {
// This `limiter` channel will receive a value
// every 200 milliseconds. This is the regulator in
// our rate limiting scheme.
limiter := time.Tick(time.Millisecond * 200)
limiter := time.Tick(200 * time.Millisecond)
// By blocking on a receive from the `limiter` channel
// before serving each request, we limit ourselves to
@@ -49,7 +49,7 @@ func main() {
// Every 200 milliseconds we'll try to add a new
// value to `burstyLimiter`, up to its limit of 3.
go func() {
for t := range time.Tick(time.Millisecond * 200) {
for t := range time.Tick(200 * time.Millisecond) {
burstyLimiter <- t
}
}()

View File

@@ -1,2 +1,2 @@
b8dbdb8d53386f00ff900fea62db400d962b4834
h9TUTv494TN
edad78bf3b36ddc9bec30b344b8a72be4de90f3b
l4uDE-RCDpa

View File

@@ -17,11 +17,11 @@ func main() {
// of time, to simulate e.g. blocking RPC operations
// executing in concurrent goroutines.
go func() {
time.Sleep(time.Second * 1)
time.Sleep(1 * time.Second)
c1 <- "one"
}()
go func() {
time.Sleep(time.Second * 2)
time.Sleep(2 * time.Second)
c2 <- "two"
}()

View File

@@ -1,2 +1,2 @@
72503557ab54ef765eeba153fe8a3446541dfc5f
Vco7d8Lmhn
8d743edffd7de6bf7bccdf4437f45672b6adc75e
ZdSOPe1Gj13

View File

@@ -15,7 +15,7 @@ func main() {
// channel that is sent values. Here we'll use the
// `range` builtin on the channel to iterate over
// the values as they arrive every 500ms.
ticker := time.NewTicker(time.Millisecond * 500)
ticker := time.NewTicker(500 * time.Millisecond)
go func() {
for t := range ticker.C {
fmt.Println("Tick at", t)
@@ -25,7 +25,7 @@ func main() {
// Tickers can be stopped like timers. Once a ticker
// is stopped it won't receive any more values on its
// channel. We'll stop ours after 1600ms.
time.Sleep(time.Millisecond * 1600)
time.Sleep(1600 * time.Millisecond)
ticker.Stop()
fmt.Println("Ticker stopped")
}

View File

@@ -1,2 +1,2 @@
5d97b8ebdf36a65f0e92040bae0097f60b79e1ed
MO3ndiv5qR
7dc6447323f493f72aa70952bf3e3f2c6156f82f
Rgc_UDvHv6a

View File

@@ -15,7 +15,7 @@ func main() {
// after 2s.
c1 := make(chan string, 1)
go func() {
time.Sleep(time.Second * 2)
time.Sleep(2 * time.Second)
c1 <- "result 1"
}()
@@ -28,7 +28,7 @@ func main() {
select {
case res := <-c1:
fmt.Println(res)
case <-time.After(time.Second * 1):
case <-time.After(1 * time.Second):
fmt.Println("timeout 1")
}
@@ -36,13 +36,13 @@ func main() {
// from `c2` will succeed and we'll print the result.
c2 := make(chan string, 1)
go func() {
time.Sleep(time.Second * 2)
time.Sleep(2 * time.Second)
c2 <- "result 2"
}()
select {
case res := <-c2:
fmt.Println(res)
case <-time.After(time.Second * 3):
case <-time.After(3 * time.Second):
fmt.Println("timeout 2")
}
}

View File

@@ -1,2 +1,2 @@
5ea69771a4d4c6286fd587f91e03cd386f77cada
NR2GHXUKeM
93343e1aacb14f818c87732914c29ba57afab245
MgcfA-xpJO9

View File

@@ -15,7 +15,7 @@ func main() {
// tell the timer how long you want to wait, and it
// provides a channel that will be notified at that
// time. This timer will wait 2 seconds.
timer1 := time.NewTimer(time.Second * 2)
timer1 := time.NewTimer(2 * time.Second)
// The `<-timer1.C` blocks on the timer's channel `C`
// until it sends a value indicating that the timer

View File

@@ -1,2 +1,2 @@
a5b44952d93152ba6bfdb100ea30cd8446cad47e
6fSHrYxpMu
e10c601ab3b702dfcea728c1edb31673561484b5
pybl9hRvJq2