In general when a hot-swap is performed:
- The new code is loaded into the system, processes with old code keep running unless a another new version is loaded, then any processes with the old code are killed (and reloaded if in the supervision tree), the system supports 2 code versions per module at a time.
- A process that has its code reloaded gets a system message sent to it telling that, the OTP behaviours (like
GenServer
) will handle that by calling your code_change function then swapping to the new code. If non-OTP you can handle that message by calling your loop function via a long call (Module.myloop
instead of justmyloop
) to swap to the new code (while doing whatever conversions you want one way or another). TheModule.blah
form always calls the new code of a module. Theblah
form calls the local version of the code of a module (take in to account Elixir imports, those are long calls). - And of course old versions can keep running too if they want, they will just be killed if they get more than one version out of date (of which a supervisor should recreate them if in a supervision tree).