The simplest answer is to write your code in a way that you can send a message to your goroutine telling it to exit. You have this already with your worker, but you don’t have it for your goroutines that it spawns. What I would suggest is to create a single channel inside of your worker that can be used to exit all of the spawned goroutines. Then when your worker function gets a message on ch1, it could then send a message out to its own exit channel telling those goroutines to terminate.
Here is a slightly tweaked version of your code that does this: https://play.golang.org/p/2H5mMKUeCj
Probably not the prettiest code but it is a quick and dirty example of what I mean.