[erlang-questions] Generic server and state recovery

Edmond Begumisa ebegumisa@REDACTED
Wed Dec 8 14:24:28 CET 2010

You could implement this functionality in to your gen_server (that is  
trapping exits) using the terminate callback, persisting the state for  
recovery later or sending it to another process just before the gen_server  
process itself exits...

init() ->
    process_flag(trap_exit, true),

terminate(normal, State) ->
terminate(_Crash, State) ->
    ok = save_crashing_state(State),

save_crashing_state(State) ->
    % do something with State

- Edmond -

On Wed, 08 Dec 2010 22:29:40 +1100, Alessandro Sivieri  
<alessandro.sivieri@REDACTED> wrote:

> 2010/12/8 Edmond Begumisa <ebegumisa@REDACTED>
>> By "recover", do you mean after an abnormal exit?
> Yes, for example after a crash, when the supervisor restarts the  
> process...

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

More information about the erlang-questions mailing list