This question already has an answer here:
- how to stop a goroutine 6 answers
I have a goroutine that calls a function and with a special parameter i want to start or stop this goroutine. My problem is that this code never stops my goroutine, it creates everytime a new job.
quit := make(chan bool)
run := make(chan bool)
go func() {
for {
select {
case <-quit:
close(run)
case <-run:
myFunc(c)
default:
}
}
}()
if x == true {
quit <- true
} else {
run <- true
}
How do I stop my routine?
</div>