Go language--time. After () 78873396
1. Source Code Analysis:
After waits for the duration to elapse and then sends the current time
On the returned channel.
It's equivalent to Newtimer (d). C.
The underlying Timer isn't recovered by the garbage collector
Until the timer fires. If efficiency is a concern, use Newtimer
Instead and Timer.stop if the Timer is no longer needed.
Func after (d Duration) <-chan time {
Return Newtimer (d). C
}
According to the note, after waiting for a given time, the return value is sent to the current time, and the return value is a one-way read-only channel
2.demo:
func main() { c := make(chan int, 1) select { case m := <-c: fmt.Println(m) case d := <-time.After(5 * time.Second): fmt.Println("time out") fmt.Println("current Time :", d) } }
Time Out
Current time:2017-12-22 15:04:05.0462009 +0800 CST m=+5.004000001
3. Analysis:
In the first case, channel C has been in a blocking state; When after () is finished, a value is taken from the return value channel given D, which is the current time
Go language--time. After ()