参考文章 http://youthyblog.com/2015/07/31/erlang-question-gen-server-and-init/
很幸运能看到这篇文章,从而获得一种新的写法。平常都是用 timeout =0 ,做一些耗时或者初始化操作。
伪代码:
start_link(Args) ->
proc_lib:start_link(?MODULE, init, [self(),Args]).
init([Parent,Args]) ->
register(?MODULE, self()),
proc_lib:init_ack(Parent, {ok, self()}),
%%do_initialization
gen_server:enter_loop(?MODULE, [], Args).
相关文章:
https://pdincau.wordpress.com/2013/04/17/how-to-handle-configuration-in-init1-function-without-slowing-down-your-erlang-supervisor-startup/
http://stackoverflow.com/questions/14648304/is-handle-info-guaranteed-to-executed-first-in-a-process-after-init-with-timeout