There was several issues: - access to field on pointer to struct from runtime: fix in lookupBinField - assign operation was skipped when performed in a comm clause - the direction of comm clause was wrong if a channel send operation was performed in a body of a receive comm clause Fixes #884.
45 lines
578 B
Go
45 lines
578 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
period = 100 * time.Millisecond
|
|
precision = 5 * time.Millisecond
|
|
)
|
|
|
|
func main() {
|
|
counter := 0
|
|
p := time.Now()
|
|
ticker := time.NewTicker(period)
|
|
ch := make(chan int)
|
|
|
|
go func() {
|
|
for i := 0; i < 3; i++ {
|
|
select {
|
|
case t := <-ticker.C:
|
|
counter = counter + 1
|
|
ch <- counter
|
|
if d := t.Sub(p) - period; d < -precision || d > precision {
|
|
fmt.Println("wrong delay", d)
|
|
}
|
|
p = t
|
|
}
|
|
}
|
|
ch <- 0
|
|
}()
|
|
for c := range ch {
|
|
if c == 0 {
|
|
break
|
|
}
|
|
println(c)
|
|
}
|
|
}
|
|
|
|
// Output:
|
|
// 1
|
|
// 2
|
|
// 3
|