How can I kill a goroutine which is blocking. An idea is that returning from the host function would be a solution but I'm not sure if this kills the goroutine or not.
func myFunc() int {
c := make(<-chan int)
go func(){
for i := range c {
// do stuff
}
}()
return 0 // does this kills the inner goroutine?
}
Is there a more nice solution? For example it would be nice that something like this work but because of the blocking for it doesn't:
func myFunc() int {
c := make(<-chan int)
closeChan := make(chan int)
go func() {
select {
case close := <-closeChan:
return 0
default:
for i := range c {
// do stuff
}
}
}()
closeChan<-0
// other stuff
}