The question/problem I have is related to handle_info/3. If anyone
sends a message to the gen_fsm, it can derail the process by resetting
the timeout timer. If I don't return a timeout from handle_info, the
process falls out of its polling/retry cycle.
I'd like to be able to say, "ignore the message" and maintain the
state (including the timeout timer) of the process. But per the docs,
there isn't a no_reply option supported by gen_fsm.
What's the Erlang Tao here? I'm tempted to call exit in handle_info
and crash and burn, but I haven't seen that pattern used in OTP for
unhandled messages. The alternative would be to return the current
state with a generic timeout to get the process back into its routine.
This feel defensive though.
Thoughts?
Some of the other OTP behaviors have an explicit 'no_reply' return
value, indicating such. Not so with gen_fsm. As far as not handling
it, does something like this look right?
handle_event(Event, StateName, State) ->
{unexpected_event, Event, StateName, State).
> As for the planned messages - don't :)
That's where I came down on this. Too much of a hassle to properly
restore the state. I think if I was concerned about handling something
like a nodedown msg, I'd create another process, registering it with
net_kernel and then notify the gen_fsm via its public API.
> Hope that helps,
Absolutely -- thanks!
These are part of the gen_fsm callbacks though -- which means
compilation warnings if they're not implemented. It's better to suffer
the warnings than to have noop functions?
Yup. I use the pattern where all messages are wrapped up behind a
public API and uses the OTP module functions for actually sending
messages. I was wondering about the catch all functions that OTP makes
you use and how "assertive" one should be with unexpected conditions.
I think I got it now :)
Thanks!