Erlang gen_fsm transition to a new state

classic Classic list List threaded Threaded
5 messages Options
shk
Reply | Threaded
Open this post in threaded view
|

Erlang gen_fsm transition to a new state

shk
Hello,

I have erlang gen_fsm, my first state:

begin({Nick}, _From, State) ->
            {reply, true, next_state, State}.
Then i have:

next_state(_Event, _From, State) ->
        io:format("Test \n")
        {reply, ok, begin, State}.
But i don't seen Test note in shell

How correctly transit to a new state?

Thank you.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang gen_fsm transition to a new state

mazenharake
The state transitions are not automatic. You have to send an event to the FSM to "drive" it.

Look at the documentation for various "send_event" functions.

/M

On 24 May 2011 10:10, Alexander Kuleshov <[hidden email]> wrote:
Hello,

I have erlang gen_fsm, my first state:

begin({Nick}, _From, State) ->
           {reply, true, next_state, State}.
Then i have:

next_state(_Event, _From, State) ->
       io:format("Test \n")
       {reply, ok, begin, State}.
But i don't seen Test note in shell

How correctly transit to a new state?

Thank you.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
shk
Reply | Threaded
Open this post in threaded view
|

Re: Erlang gen_fsm transition to a new state

shk
Hello,

Thank you for reply.

I do in

I have erlang gen_fsm, my first state:

begin({Nick}, _From, State) ->
           gen_fsm:send_event({global, State#state.id}, {start, Nick}),
           {reply, true, next_state, State}.
Then i have:

next_state({start, Nick}, State) ->
       io:format("Test \n"),
       {reply, ok, begin, State}.

But it's doesn't work.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
shk
Reply | Threaded
Open this post in threaded view
|

Re: Erlang gen_fsm transition to a new state

shk
Can i have any state_name/3 || /2 functions with different names?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang gen_fsm transition to a new state

mazenharake
If you start a gen_fsm init() will be called

init() -> {ok, foo, undefined}.

Next message you send with send_event() to the gen_fsm will be handled by foo()

foo(_, _) -> {next_state, bar, undefined}.

Next message will be handled by bar()

bar(_, _) -> {next_state, foo, undefined).

Next message will be handled by foo().

If you use sync_send_event() instead then these functions must be of arity 3 since you get a "From" variable with them.

so, yes you can mix them but they are called differently.

And don't use a sync_send_event() from inside a callback function because you will deadlock.

/M



On 24 May 2011 10:45, Alexander Kuleshov <[hidden email]> wrote:
Can i have any state_name/3 || /2 functions with different names?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions