如何在GO中关闭动态Chan

Sorry, I can't come up with more explaining thread title.

I'm new at GO and I started from rewriting my app from python to GO because I need pure threads. Idea: I've queue where I'm put some initial objects with method X. While iterating this queue I'm calling this method X for each object in it. This method X returns more objects with method X between zero and Y, where Y is unknown. This method X should be threaded and loop should sleep while there's no objects, until all goroutines finishes and no more objects in queue. I did initial code, it's working almost as expected, but I dont realize how to check goroutines finished and queue is empty. First try was waitgroup, but it's don't have methods like IsEmpty or Count cause it's threadsafe. Can anyone recommend me any techniques for my problem?

Here is the code https://play.golang.org/p/-t7hszVmnG if you need not cached result add some number for UnixNano in line 50.

Thanks in advance!