I would like to know how to kill/stop goroutines. All examples are based on channels and select, which seems to only work if the goroutine contains some repeating task between which it can listen on a channel. Is there a way to stop the below goroutine before it returns?
package main
import (
"time"
)
func main() {
stop := make(chan string, 1)
go func() {
time.Sleep(10 * time.Second)
stop <- "stop"
return
}()
<- stop
}