Complete newbie here trying to write a small library/module for interacting with a certain API and I'm having trouble structuring things
the interface I'm aiming for looks something like this:
defmodule Connection do
def start_link(_arg) ... end
def send(pid, ws, message) ... end
def subscribe(pid, ws, message_type) ... end
def unsubscribe(pid, ws, message_type) ... end
end
You'd call start_link, get a PID back and call the other functions with it etc
the API itself is rather strange and requires a client to be connected to two separate websockets at the same time so to try to make things simple I'm using a one_for_all supervisor to restart both whenever one fails
- connection_serv (keeps track of and serves messages to subscribers)
- connection_ws_sup (one_for_all, started by connection_serv)
- connection_ws0 (relays msgs to connection_serv)
- connection_ws1 (relays msgs to connection_serv)
What I'm confused about is how connection_serv and connection_ws_sup should be "linked" together. I feel like the right thing to do here is to add another supervisor but then the server wouldn't be the "root" process anymore, and I'd have to be able to somehow reach the server with the supervisor's PID to implement the above interface. Should I just link the two processes together instead?