Get data out of module using WebSockex
Closed this issue · 2 comments
It doesn't appear to me that there is any way to get information out of the module using WebSockex short of :sys.get_state(pid)
. I'm trying to use WebSockex with an events api where the local side of the connection builds up a rather large state of the world. Instead of dispatching the full state to separate worker processes when key events happen, I would like to ask for small bits of state when needed.
An example of what I'd like to do is get the profile of a user from the list of 1000s maintained in the module state. Since GenServer was a thought for implementation at one point, is the call
functionality of GenServer something on the plate to add?
If not, is the intended interaction here for the WebSockex module to forward events as they are received to a separate process that can have the interface for querying reduced information of state?
You more or less stumbled upon the implicit and unstated design that I had in mind.
Basically, I don't want to prevent you from doing what you want to do and easily enough you could build that behavior into your module.
The choice not to implement call
was a nudge in the direction of not doing too much in the WebSockex process. In particular the process won't always have a live connection and doesn't want to miss time critical frames. The easiest way to avoid those problems is to not make them the callback's responsibility.
HOWEVER, there are instances where it just makes the most sense to do it that way. So I didn't prevent someone from implementing that type of rpc functionality (using handle_info
or handle_cast
and replying appropriately).
But, the nudge is the fact that most of the time it is just easier to do what you described instead. As a result you forward them to another interface that doesn't care about the workings of the WebSocket. That in my opinion is the better design decision in this situation anyway, but I don't want to tell you that you HAVE to do it that way.
Sorry that it's kind of a half answer but the answer is just, "If you want to implement that kind of behavior then do it, if there's anything stopping you then it's a bug. In my opinion, you probably don't want to do it that way."
I went with the separate process and I agree that it is a better design. As I’m just getting acquainted with Elixir and Erlang the last couple weeks I wasn’t immediately sure how to solve my problem, but typing the question above gave me the idea. It is reassuring to see that was the intent.