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 | Description |
|---|---|
push-button | Basic state transitions, synchronous calls, press counter |
simple-door-lock | Shows how to use 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.
Door Lock
A code-protected door lock. Also an example from the docs.
- 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.
Event Handler (gen_event)
| Example | Description |
|---|---|
terminal-logger | Fan-out broadcasting via notify, multiple handlers with independent state, on_terminate cleanup |
Terminal Logger
A pair of gen_event handlers wired to a single event bus. Modelled after the canonical error_man example from the OTP docs.
add_terminal_logger: prints each event to stdout and tracks a countadd_file_logger: appends each event to a file pathreportbroadcasts to every registered handler in one call