Gen_fsm timeout resolution if it does not receive messages

Normally, if I wanted to have an Erlang process timeout, I would use the following construction:

receive 
    Msg -> ok; %% handle message
after 60000 ->
    %% Handle timeout and exit
end.

Is there a similar mechanism on OTP servers like gen_fsm? I will generate gen_fsm for each active session with my application and would like them to exit if the timeout value for inactivity is exceeded after receiving the message.

I can write my own process if necessary, but prefer to use gen_fsm if possible.

+5
source share
1 answer

I also dug up and found the answer to my question.

"" , , -.

:

some_fsm_state({set, Val}, State) ->
    NewState = do(Val, State),
    {next_state, another_fsm_state, NewState, 5000};

another_fsm_state(timeout, State) ->
    handle_timeout(State).

another_fsm_state({set, Val}, State) ->
    %% more code that handles this state.

some_fsm_state, "another_fsm_state" - 5000 . 5000 , other_fsm_state (timeout, State).

OTP.:)

, . . Erlang.

Erlang - Hibernate

gen_fsm docs

+11

All Articles