I'm trying to build a function that I pass a channel to and when run in a go routine it will constantly post updates (in this instance, values of sin) to a channel. When data is sent the the channel, I then want to send it over a web socket.
func sineWave(value chan float64) {
var div float64
sinMult := 6.2839
i := 0
log.Println("started")
for {
div = (float64(i+1) / sinMult)
log.Println(math.Sin(div))
time.Sleep(100 * time.Millisecond)
value <- math.Sin(div)
// log.Println()
i++
if i == 45 {
i = 0
}
}
// log.Println(math.Sin(div * math.Pi))
}
It seems to get stuck at value <- main.Sin(div)
stopping the rest of main() from running. How do i get sineWave to run indefinitely in the background and to print its output in another function as they arrive?