Running code when a script exits

Thanks @josevalim!

However, System.stop/1 has three problems:

  1. It does not invoke System.at_exit/1, that is why my “halter” solution above needs to get passed a function.
  2. The script ends printing the noisy “exit” traces I quoted above. Maybe that is cosmetic, but a user does not know if “no process: the process is not alive or…” is a normal message or something to worry about, and in any case the output is not clean as you’d expect from running a program that finishes normally.
  3. The programmer needs to do this by hand. I am touching a file to finish the script! Alternatively, I could write a signal handler, but all this seems boilerplate for something mix run should have builtin in my view.

The question is: mix run starts the application by default, why does not provide a builtin way to cleanly stop the application too?