tick
is a channel in Go. If you look at the docs, tick
should send something to the channel once each time interval, which is specified by time.Duration(1000/config.Samplerate) * time.Millisecond
in your code. <-tick
just waits for that time interval to pass.
i
keeps track of how many seconds pass, so every time it ticks, you add one to i
. The if statement checks when one minute passes.
So, the code inside the if statement fires every 60 seconds, while the code right under the if block fires every second.
1
solved Go lang, don’t understand what this code does