From GenServer — Elixir v1.13.1
If the caller catches the failure and continues running, and the server is just late with the reply, it may arrive at any time later into the caller’s message queue. The caller must in this case be prepared for this and discard any such garbage messages that are two-element tuples with a reference as the first element.
Does this mean the GenSever will still send response back eventually after timeout?
But from my test, I don’s see any response back.
defmodule ProcessThatTimesout do
use GenServer
def start_link() do
GenServer.start_link(__MODULE__, nil)
end
def init(opts), do: {:ok, opts}
def handle_call(:long_call, _from, state) do
:timer.sleep(2000)
IO.inspect("wake and send message back")
{:reply, "I am wake up now hhh", state}
end
end
iex(8)> {:ok, pid} = ProcessThatTimesout.start_link()
{:ok, #PID<0.248.0>}
iex(9)> :gen_server.call pid, :long_call, 1000
** (exit) exited in: :gen_server.call(#PID<0.248.0>, :long_call, 1000)
** (EXIT) time out
(stdlib 3.16.1) gen_server.erl:247: :gen_server.call/3
“wake and send message back”
From the message, the hand_call eventually returned and I expected got response from iex.
But iex flush return nothing.
iex(9)> flush
:ok
Thanks!