开发者

Code hot swapping in Erlang

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?


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 hot 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜