0
votes

Is it considered bad practice to have parent_pid argument on most handlecast and handleinfo functions in production ?

I am testing like this:

parent = self()
GenServer.cast(UserServer.via_tuple(user.id), {:update_direct, parent})
assert_receive :updating_failed, 2000

And then genserver(with simple retry mock):

def handle_cast(..... parent) do
   case updated do
     false -> Process.send_after(self(), {:update_retry, ... parent, retries + 1}, 500)
     true -> ...
    state
   end
end

And finally in handle_info :update_retry I send message back to awaiting test(parent):

send parent, :updating_failed
1
I'm not 100% sure what you want to achieve, and why. At the same time, sending out a pid (whether it's parent or not) to reply to sounds legit to me.cdegroot

1 Answers

1
votes

If you want to reply back to a parent process, then you should be using handle_call:

def handle_call(data, from, state) do
  case updated do
       false -> Process.send_after(from, {:update_retry, ... parent, retries + 1}, 500)
       true -> ...
      state
  end
  {:reply, :ok, state}
end