Please see the following example.
type runner struct{}
func (r *runner) StopProcessing() {
// how to stop?
}
func (r *runner) StartProcessing() {
go func() {
for {
fmt.Println("doing stuff")
time.Sleep(1 * time.Second)
}
}()
}
As you can see I have a struct which does stuff, it's "running". It starts running when I call the run.StartProcessing()
method. It then fires an endless running for{}
-loop in a goroutine. Great, but I also want to be able to stop this process. And I really don't know how to achieve this. Any help is highly appreciated.