I'm reading the code that package time
, and then I want to know how the func After(d Duration) <-chan Time
works.
I found the code follows:
func After(d Duration) <-chan Time {
return NewTimer(d).C
}
func NewTimer(d Duration) *Timer {
c := make(chan Time, 1)
t := &Timer{
C: c,
r: runtimeTimer{
when: nano() + int64(d),
f: sendTime,
arg: c,
},
}
startTimer(&t.r)
return t
}
So I found the definition of startTimer
- it's so weird that function startTimer
does not have a function body.
func startTimer(*runtimeTimer)
I want to know that :
- Where is the real code of
startTimer
- Why an "abstract method" can exists here
- Why the author of Go wrote it like this
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…