I'm trying to write a program to manage a shared resource for which I need
blocking function call semantics on the logic handling the resource. E.g.
if I want to implement a hit counter for a website, I would need a blocking
`increment_counter()` method which would update the counter and return me
the new value. I was using a mutex for my application, but that wasn't
working out well.
The other approach I tried was to have a goroutine manager the counter as
its internal state. To provide blocking function call semantics, I also
pass it a "response channel" along with other arguments. The manager
goroutine must manipulate the counter state and return the updated value on
that "response channel". Here's an example of how I'm using the "response
channel" for this: http://play.golang.org/p/nqfAeVzeOj
Is this a recommended pattern for managing shared state with Go? Should I
be doing a higher level refactoring to get around the requirement of
blocking function call semantics instead?
PS: Please excuse me if this has been discussed before. I just couldn't
figure out what the right search terms should be.