Examples
Runnable example projects for the eparch library. Each example is a self-contained Gleam project with unit / integration tests.
cd examples/<example>
gleam test
State Machine (gen_statem)
| Example | Concepts demonstrated |
|---|---|
01-push-button | Basic state transitions, synchronous calls, press counter |
02-door-lock | with_state_enter, StateTimeout for auto-lock, wrong-code tracking |
Push-Button
The canonical OTP gen_statem example from the official docs.
- A button toggles between
OffandOn. - Only
Off -> Ontransitions increment the press counter.
stateDiagram
Off --> On : push (count + 1)
On --> Off : push
Door Lock
A code-protected door lock.
- Entering the correct code opens the lock.
- The door auto-relocks after a configurable timeout via
StateTimeout. - Demonstrates
with_state_enterto arm the timer on every entry to theOpenstate.
stateDiagram
Locked --> Open : correct code
Open --> Locked : timeout
Locked --> Locked : wrong code (attempts + 1)
eparch/gen_event
Coming soon.