Answer the question
In order to leave comments, you need to log in
How to start the timer ( time.NewTimer) again several times?
Hello everyone, I want to restart the timer until the event is added
There was an idea, but it did not work.
func main() {
var i = 0
timer := time.NewTimer(time.Second * 1)
select {
case <-timer.C:
if i != 3 {
println(i)
i++
timer.Reset(time.Second * 1)
}
}
println(i)
}
Answer the question
In order to leave comments, you need to log in
You didn't add a loop here. Accordingly, your code runs once and exits.
What for to you in general here 3 times the timer to launch? Why not just start the timer at the desired end time?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question