func main() {
statusChannel := make(chan bool)
go checkChannel(statusChannel)
[...]
if x == 1 {
statusChannel <- true
} else {
statusChannel <- false
}
func checkChannel(statusChannel chan bool) {
defer close(statusChannel)
for {
log.Printf("waiting for signal...\n")
shouldContinue := <-statusChannel
if !shouldContinue {
log.Print("received false, breaking...\n")
gocron.Clear()
break
}
gocron.Every(1).Minute().Do(myFunc)
<-gocron.Start()
log.Print("working...\n")
}
}
The running gocron job will break, but if my gocron job starts a second time later, it runs my function two times per minute. Where is my mistake?