tuxychandru/pubsub — pull request #4 by btittelbach (2013-02-12 04:16:56+00:00)
Title: Avoid duplication of empty topic maps, separate data into contexts

Hi,

I'm new to go and just found your extremely useful pubsub go-code and took the opportunity to improve a bit on it.
As I understand it, all goroutine are closures, meaning they duplicate all data they need to run. Thus if you share your PubSub struct with many other goroutines, each one will have the same pointers to the channels but also a separate empty copy of the two topic maps.

I though this could be avoided by (also) cleanly separating the topic maps (only needed in context of the start goroutine) from the chans (needed everywhere).

In theory the topic maps could now be created on the stack of start instead of the heap with "new" and thus the cleanup up for-loop at the end of start could be removed. However I left it in there, since is also explicitly closes the chans, which otherwise might (?) not happen if other threads still have a pointer to those chans.

kind regards,
btittelbach