So, I’m extremely new to Elixir. In order to communicate with processes, you can of course use send(target_pid, message).
But, in general for this to work, you need:
The target process to persist its existence for as long as you need it to receive the messages (if it doesn’t exist, it can’t handle/reply to messages sent to it, etc).
It needs to have functions that can scan the message box and handle the messages.
GenServer of course injects your custom modules with code to ensure the above two requirements are satisfied.
Otherwise you’d have to code for the above yourself.
But, what about (custom modules that use) non-GenServer OTP modules?
How do you communicate with things like Supervisor processes, etc? I’ve tried to make my custom modules that use Supervisor (and separately, Registry) able to send/receive/handle/reply to messages, but can’t seem to pull it off.
I’ve tried to look up how to achieve it, but haven’t found much.
Again, if I create a custom module that uses Supervisor, I could potentially custom-code the persistence and message-handling features for its processes of a GenServer, but that seems superfluous.
Is there a way to perhaps combine GenServer & other OTP modules to combine their functionality, e.g. ‘use GenServer, use Supervisor’; or perhaps does this automatically happen (I.e. do most other OTP modules come with GenServer functionality); do other OTP modules have their own way of allowing you to communicate with their processes? I’ve tried to research for answers, but have found little.
Again though, being so new, I’m sure I’ve probably missed what will turn out to be the obvious answer to this.
What are your thoughts?
Many thanks indeed, really appreciate it!