Pretty State Machine
summary
gen_statem exposes concrete features GenServer lacks: multiple actions on a transition (reply, emit events, set timeouts), the ability to postpone (replay) incoming messages into the front of the mailbox, and three timer types (event, state, generic) that differ in cancellation semantics. Performance measures claim parity with GenServer, there is an upgrade path from gen_fsm, and practical examples include an HTTP-client modeled as states where postponed requests queue and timers handle retries — the patterns work in practice.
AI-written summary · about
chapters (24)
- 0:00Intro
- 0:48Premise
- 1:07Objective
- 1:51Performance
- 2:22Documentation
- 3:26State
- 3:45Data
- 4:56Action
- 6:26Genesis
- 7:02Comb Home
- 7:19Mission
- 8:16State Functions
- 8:52State Name
- 10:29State Enter Functions
- 11:39Mailbox Events
- 12:32postpone
- 13:30selective receive
- 15:19eventtimeout
- 15:52statetimeout
- 16:27responsetimeout
- 18:56generictimeout
- 19:39reversibility
- 20:57resources
- 22:56intuition
related talks
23mElixir GenServer: Understanding Elixir concurrency model
05mFun with processes
18mHold My State: The Problems of Process State
20mUsing OTP in Your Phoenix App
45mTesting Asynchronous OTP
25mLeveraging GenStage to Implement Your Own Event Bus
44mThe NeverEnding Application
37mKeynote: All Aboard The Stateful Train
