Skip to content

Conversation

@ashanbrown
Copy link

@ashanbrown ashanbrown commented Oct 31, 2017

I wanted to offer an alternate implementation for #33. This version closes a channel to signal that the event stream and error channels should be closed and it eliminates all the mutexes. It's nice not to have to reason about the mutexes. As I've coded, this refactor, I think key to using channels to avoid mutexes seems to me to be that we keep all the channel write and close operations in the same place so that it's very clear that only a single goroutine can ever be responsible for closing a channel and that we'll never write to a closed channel. The other change this PR makes is to allow us to close channels without waiting for the blocking read from the server to complete. There is still the possibility that go routines will never terminate because non-blocking reads never complete but I don't think that's a new behavior.

Glancing at the server side code, I'd suggest a similar refactor, potentially eliminating all the mutexes there as well (I suspect this related to #31). My application only uses the client-side code so I don't have a way to test that with much confidence, although I'd be willing to take a stab at it if there is sufficient confidence in the test suite (or if someone is interested in testing it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant