Skip to content

Latest commit

 

History

History
91 lines (71 loc) · 3.64 KB

otp_cheatsheet.adoc

File metadata and controls

91 lines (71 loc) · 3.64 KB

OTP Cheatsheet

Erlang e logo

The details of OTP that you may have forgotten or never known!

Behaviors

gen_server

For implementing the server of a client-server relation

gen_statem

For implementing state machines

gen_event

For implementing event handling functionality

supervisor

For implementing a supervisor in a supervision tree

Application Types

Applications

Regular applications that define their own supervision tree

Libraries

A simple collection of modules and doesn’t implement an application behavior callback module

Start Types Affect on Runtime when Application Terminates

temporary

Termination is reported but no other applications are terminated

transient

If application terminates abnormally all other applications and the runtime system are terminated

permanent

All other applications and the runtime system are terminated

Supervisors

The supervisor’s maximum restart intensity limits the number of restarts that can occur within an period of time. Restart intensity is specified as a map with two keys - intensity and period. Restarts are limited to the to number specified by intensity that occur within the number of seconds specified by period.

Child specs are maps with the following keys:

Key Optional Description

id

required

An identifier to use for the process

start

required

The MFA to use to start the process

restart

optional

See the restart types

shutdown

optional

brutal_kill or an integer timeout for workers. Must be infinity for supervisors.

type

optional

See the child types

modules

optional

The callback module if there is one

Child Types

worker

Any process that is not a supervisor

supervisor

A supervisor process

Restart Types

permanent

The process is always restarted

temporary

The process is never restarted

transient

The process is only restarted if it terminates abnormally

Restart Strategies

Strategy Description

one_for_one

If one child process crashes only restart that process

one_for_all

If one child process crashes all other child processes are terminated and all of them are restarted

rest_for_one

If one child process crashes the rest of the child processes are terminated and the crashed process and other terminated processes are restarted

simple_one_for_one

Like the one_for_one strategy, but it can only dynamically start processes from a single child spec