Che*_* Yu 3 erlang message-queue gen-server
在编写代码时,我会问自己应该使用call哪种类型的消息,应该使用哪种类型的消息info?
在这个问题下面,还有另一个长期怀疑info, cast, call消息之间是否存在优先级差异?这3种消息是否共享同一队列?
消息的优先级是相同的.快速查看gen_server.erl,您将发现接收所有数据的简单循环.
loop(Parent, Name, State, Mod, hibernate, Debug) ->
proc_lib:hibernate(?MODULE,wake_hib,[Parent, Name, State, Mod, Debug]);
loop(Parent, Name, State, Mod, Time, Debug) ->
Msg = receive
Input ->
Input
after Time ->
timeout
end,
decode_msg(Msg, Parent, Name, State, Mod, Time, Debug, false).
Run Code Online (Sandbox Code Playgroud)
关于handle_info:
当发生超时或接收除同步或异步请求(或系统消息)之外的任何其他消息时,gen_server会调用此函数.
例如,timeout,tcp,udp,EXIT,sytem info以及许多其他不适合handle_call或handle_cast的信息.