关于golang中time.After()的返回值是什么?
package main
import(
"fmt"
"time"
)
func say(s string){
for i := 0;i < 5;i++{
fmt.Println(s)
}
}
func main() {
a := time.After(time.Second * 2)
fmt.Printf("%T",a)
}
输出的结果为:
<-chan time.Time
上面的结果说明time.After()的返回值是一个 chan 类型。
但是我看了time.go的源码,包括github上面的go语言源代码(time.go),发现After()的源码如下:
// After reports whether the time instant t is after u.
func (t Time) After(u Time) bool {
if t.wall&u.wall&hasMonotonic != 0 {
return t.ext > u.ext
}
ts := t.sec()
us := u.sec()
return ts > us || ts == us && t.nsec() > u.nsec()
}
time/sleep.go