Closing connection
Hi,
Is it possible to close connection, so that I can create new app, without previously connected websocket hanging around?
Basically I want to dynamically register and unregister entity listeners based on user's actions. Since I expect this to happen relatively rarely, it's fine for me to create new app every time I need to change entities, however currently I don't see any way to stop app (from another goroutine), after calling app.Start()
Unless app.Cleanup() does that, but as far as I can tell, it just cancels the context. Does that close the websocket? Sorry for stupid question, I don't really understand how contexts work.
Alternatively, unregistering events would be fine for my use-case, but I expect that just closing connection and starting a new one will be less work to implement and less bug-prone in the future.
Thanks for great library and have a nice day!
Hm I don't think it will work if you call cleanup, I didn't have this in mind when I wrote it. I don't have much time to work on this right now but will leave open in case I have time later or anyone wants to contribute.
Okay, I will try to implement this and make a pull request when it's ready.
I think it should be app.Close(), to be consistent with http server.Close(), since from what I can tell, homeassistant doesn't expect any closing message. It would just close websocket connection. Then, I could just create new app, and garbage collector should take care of old app.
Have a nice day!
Sounds great!
FYI @mhagger I think some of the changes you're making (or maybe have already made) will address this feature request.
That's right, part of my giant patch series includes code that allows listeners to be added and removed at will. That PR has bitrotted but I'm trying to submit that functionality again, piece by piece. I'm right now working on a re-roll of the subscriber interface and hope to push something soon.
@LukaszMoskala: I just pushed two PRs that allow subscribing and unsubscribing to particular message IDs (at the Conn level): #42 and #43. I'm not sure that gets you all the way where you want to be, but maybe you can get by with it for now? More is coming, hopefully on a time scale of weeks but no promises. If you have any feedback, please let me know.