Behavior and helpers for pluggable chat state storage.
State adapters own subscriptions, dedupe windows, and per-thread / per-channel state maps. The default adapter keeps everything in memory, but adapters may persist state elsewhere as long as they can expose a normalized snapshot.
Summary
Functions
Returns channel state map from adapter-managed state.
Returns the canonical empty snapshot.
Returns true when a message dedupe key has already been seen.
Force-releases a lock regardless of owner and returns pending entries.
Initializes adapter state from a normalized snapshot.
Attempts to acquire a concurrency lock for the given key and owner.
Records a new dedupe key and trims state to the requested limit.
Normalizes maps, lists, and map-sets into the canonical state snapshot shape.
Writes channel state map into adapter-managed state.
Writes thread state map into adapter-managed state.
Releases a held lock and returns any queued/debounced pending entries.
Returns a normalized snapshot for adapter-managed state.
Adds a subscribed thread id to adapter-managed state.
Returns true when the thread is subscribed in adapter-managed state.
Returns thread state map from adapter-managed state.
Removes a subscribed thread id from adapter-managed state.
Types
@type lock_result() :: :acquired | :queued | :debounced | :busy
@type release_result() :: {:released, [map()]} | {:error, :not_owner}
@type snapshot() :: %{ subscriptions: MapSet.t(String.t()), dedupe: MapSet.t(dedupe_key()), dedupe_order: [dedupe_key()], thread_state: %{optional(String.t()) => map()}, channel_state: %{optional(String.t()) => map()}, locks: %{optional(String.t()) => map()}, pending_locks: %{optional(String.t()) => [map()]} }
@type state() :: term()
Callbacks
@callback duplicate?(state(), dedupe_key()) :: boolean()
@callback mark_dedupe(state(), dedupe_key(), pos_integer()) :: state()
@callback release_lock(state(), String.t(), String.t()) :: {release_result(), state()}
Functions
Returns channel state map from adapter-managed state.
@spec default_snapshot() :: snapshot()
Returns the canonical empty snapshot.
@spec duplicate?(module(), state(), dedupe_key()) :: boolean()
Returns true when a message dedupe key has already been seen.
Force-releases a lock regardless of owner and returns pending entries.
Initializes adapter state from a normalized snapshot.
Attempts to acquire a concurrency lock for the given key and owner.
@spec mark_dedupe(module(), state(), dedupe_key(), pos_integer()) :: state()
Records a new dedupe key and trims state to the requested limit.
Normalizes maps, lists, and map-sets into the canonical state snapshot shape.
Writes channel state map into adapter-managed state.
Writes thread state map into adapter-managed state.
Releases a held lock and returns any queued/debounced pending entries.
Returns a normalized snapshot for adapter-managed state.
Adds a subscribed thread id to adapter-managed state.
Returns true when the thread is subscribed in adapter-managed state.
Returns thread state map from adapter-managed state.
Removes a subscribed thread id from adapter-managed state.