You likely want something like this, https://gist.github.com/1075298
When you use WaitGroup you have to be careful not to get in the way of
any channel communication.
You'll get deadlocks if you're waiting for a goroutine to end and that
goroutine is waiting to send on a channel.
> I have tried using sync.WaitGroup (wg.Add(1) at line 8.5 and wg.Done
> in a defer'd func in processServer, and then wg.Wait()'ing before
> shutting down the output goroutine, but this lead to a deadlock (I'm
> at a loss to understand this), so I've ended up just waiting a small
> amount of time at critical points (which seems very kludgy) and
> watching the buffer channel's length.
>
> Suggestions about this setup (including approach to communication
> between the goroutines) and how to improve it are appreciated.
>
> thanks
> Dan
--
=====================
http://jessta.id.au
The core of processServer is this
func processServer(index *interval.Tree, queue, output chan
*feat.Feature[, optional wg *sync.WaitGroup here]) {
[define vars]
for feature := range queue {
[do stuff]
output <- feature
}
[optional wg.Done() here]
}
thanks for your time.
Dan