Use a channel to trigger stopping of streaming #36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).