views:

229

answers:

1

I recently saw a video about Erlang on InfoQ, In that video one of the creators presented how to replace the behavior of a message loop.

He was simply sending a message containing a lambda of the new version of the message loop code, which then was invoked instead of calling the old loop again.

Is that code hot swapping in Erlang reffers to? Or is that some other more native feature?

+3  A: 

Yes, hot swapping in erlang servers generally refers to this feature. It is well explained in the stackoverflow question Achieving code swapping in Erlang’s gen_server, and also in this neat Erlang Generic Server tutorial or this little one.

The Erlang/OTP gen_server module provides a generic way to achieve how swapping, by implementing a Module:code_change/3 function in the callback module.

This way, you can upgrade a servers code without shutting it down, or fall back to former implementation if something does not work as expected. In general, hot swap should be put in place using the generic release handler.

tonio