ExGram.FSM.Storage.ETS (ExGram FSM v0.1.0)

Copy Markdown View Source

Default in-memory FSM storage using ETS.

Suitable for development and single-node deployments. State is lost on application restart.

Bot-scoped tables

Each bot gets its own ETS table, named :"ex_gram_fsm_{bot_name}" by default. This ensures multiple bots running in the same node do not share FSM state. Override the table name via the :ets_table option:

use ExGram.FSM, storage: ExGram.FSM.Storage.ETS, ets_table: :my_custom_table

Concurrency

Single-key ETS operations (get_state, set_state, clear) are atomic. However, update_data/3 and set_data/3 are read-modify-write operations and are not atomic. If you need atomicity for concurrent updates to the same key, use a storage backend with proper transactions (Postgres, Mnesia, etc.).

Table ownership

The ETS table is created as :public and :named_table in init/2. The table is owned by the process that first calls init/2. If that process dies, the table is destroyed.

For production use, consider wrapping the table in a GenServer in your supervision tree to ensure stable ownership.