OTP Cheatsheet

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

Applications

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

Restart Intensity

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

Child specs are maps with the following keys:

Key Optional Description

id

required

An identifer 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

::...
免责声明:
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
内容版权归原作者所有;
本人对内容的有效性/合法性不承担任何强制性责任.
若有不妥, 欢迎评注提醒:

大妈的多重宇宙 - YouTube

全新自媒体:科幻/读书/说故事...欢迎订阅;

或是邮件反馈可也:
askdama[AT]googlegroups.com


订阅 substack 体验古早写作:
Zoom.Quiet’s Chaos42 | Substack


点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:
zoomquiet



粤ICP备18025058号-1
公安备案号: 44049002000656 ...::