erlang - Receive after result not returned -
given function:
%% @doc retrieves client's state. -spec(state(pid()) -> atom()). state(pid) when is_pid(pid) -> case process_info(pid) of undefined -> undefined; _else -> pid ! {state, self()}, receive {state, state} -> state after 1000 -> undefined end end.
it works expected dead pids , alive clients:
> client:state(a). undefined > client:state(pid). online
but reason returns pid if process pid not reply status during 1 second:
> client:state(self()). <0.172.0>
i'm expecting 'undefined' atom there. how can fix code?
this happens because receiving message sent. function running on shell process , sends {state, self()}
message. right after sending message, receives message , function ends state
, self()
pid sent.
i hope i've not been confusing.
Comments
Post a Comment