Trouble with init/1 spec

Magnus Henoch magnus@REDACTED
Wed Mar 24 17:20:52 CET 2010


Jay Nelson <jay@REDACTED> writes:

> I am having trouble specifying an init/1 function.  This should be a
> problem for most gen_xxx applications that use records for State, so
> I must have not used the right query terms to search the archives.
>
> Here is my init/1 function for a gen_fsm:
>
> -spec init(list()) -> {ok, ?RECONNECT, #twfsm_state{}}.
> 		
> init([Server, Port, User, Pwd]) ->
>     {ok, ?RECONNECT,
>      #twfsm_state{server=Server, port=Port, user=User, pwd=Pwd}}.

My favourite fix for that is to pass a tuple instead of a list.
gen_{server,fsm}:start_link accept any term as the argument, and pass it
unchanged to the init callback function, so I don't really see any
reason to use a list there.

-- 
Magnus Henoch, magnus@REDACTED
Erlang Solutions
http://www.erlang-solutions.com/
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com



More information about the erlang-questions mailing list