at the moment I am using a for loop like this
for ; true; <-time.After(duration)
the first time it is executed instantly, then by <-time.After(duration)
Now I need to rewrite this function so that I can stop it with a channel. By default, this is done using select, but it waits for the <-time.After(duration) already at the first iteration
for {
select {
case <-done:
return
case t := <-time.After(duration):
fmt.Println("Tick at", t)
}
}
how i can solve it?
select
on thedone
channel with adefault
case that is empty, e.g. go.dev/play/p/3QuY40ikkKndone
channel?