I’m currently working on a
GenServer that uses erlexec to talk to an external binary over stdin/stdout. So I already have a
handle_call that associates a “command” with the output of the program (which involves a timeout to know when the “command” is done running). The problem is that within that
handle_call I want to execute another “command”.
The “easiest” way to accomplish that would be by using
handle_call. But of course that will not work because a
GenServer cannot call itself since that would result in a deadlock. Another possibility that might work is to spawn a
Task, and that task can run the
GenServer.call, that way the deadlock can be avoided.
But my question is this: By even posing this problem is it indicating a fault in my design? Should there be an easier way from within the
GenServer process to share the code path that sends the “command” to the erlexec process along with the debounced timeout behavior? Should I introduce another GenServer and have that GenServer be responsible for the “higher-level” protocol (which is why I currently want to execute a “command” during a
handle_call). Curious to know any thoughts.