The documentation suggests doing this:
go pubInstance.Publish(<pubnub channel>, <message to publish>, callbackChannel, errorChannel)
go ParseResponse(callbackChannel)
go ParseErrorResponse(errorChannel)
It appears that Publish() will only send messages on one of the two channels. And (like a good Go receiver) never closes the channels that it receives.
Won't this lead to leaking at least one goroutine for every single Publish?
See, at least one of those two goroutines will block on <-myChannel, which means that goroutine will never be freed.
Wouldn't it make more sense to use a select{} on those two channels and react to whichever one returns first? And probably having a time.Timer to timeout long requests would be a good idea, too, right?
The documentation suggests doing this:
It appears that Publish() will only send messages on one of the two channels. And (like a good Go receiver) never closes the channels that it receives.
Won't this lead to leaking at least one goroutine for every single Publish?
See, at least one of those two goroutines will block on
<-myChannel, which means that goroutine will never be freed.Wouldn't it make more sense to use a
select{}on those two channels and react to whichever one returns first? And probably having atime.Timerto timeout long requests would be a good idea, too, right?