每隔1秒打印一下时间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package main

import (
"fmt"
"time"
)

func main() {
ticker := time.NewTicker(time.Millisecond * 1000)
go func() {
for t := range ticker.C {
fmt.Println("Tick at", t)
}
}()
select {} // select 就好
}