Skip to content

Instantly share code, notes, and snippets.

@OvermindDL1
OvermindDL1 / discussion.md
Created June 28, 2018 17:03 — forked from jadeallenx/discussion.md
When does terminate/2 get called in a gen_server?

When does terminate/2 get called in a gen_server?

This is what the [official documentation][1] says about the terminate/2 callback for a gen_server:

This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.

Reason is a term denoting the stop reason and State is the internal state of the gen_server.

Reason depends on why the gen_server is terminating. If it is because another callback function has returned a stop tuple {stop,..}, Reason will have the value specified in that tuple. If it is due to a failure, Reason is the error reason.

Keybase proof

I hereby claim:

  • I am overminddl1 on github.
  • I am overminddl1 (https://keybase.io/overminddl1) on keybase.
  • I have a public key whose fingerprint is C5A2 9446 51E5 EFF1 AEB9 5848 3AB7 DC53 B699 3840

To claim this, I am signing this object: