Raxol.Core.CompilerState (Raxol v2.6.0)

View Source

Thread-safe ETS table management for Raxol's plugin command registry.

Atomic ETS operations are guarded with try/rescue ArgumentError to cover the race window where another process deletes the table between the existence check and the operation. ETS lookup/insert/delete are atomic and microsecond-scale; no process isolation is needed.

Summary

Functions

Ensures an ETS table exists, creating it if missing.

Safe ETS delete by key. Returns :ok or {:error, :table_not_found}.

Safe ETS table deletion. Returns :ok or {:error, :table_not_found}.

Safe ETS insert. Returns :ok or {:error, :table_not_found}.

Safe ETS lookup. Returns {:ok, rows} or {:error, :table_not_found}.

Functions

ensure_table(name, opts \\ [:named_table, :public, :set, read_concurrency: true])

@spec ensure_table(atom() | :ets.tid(), list()) :: :ok | {:error, term()}

Ensures an ETS table exists, creating it if missing.

Idempotent. Returns :ok if the table already exists or was created.

safe_delete(table, key)

@spec safe_delete(atom() | :ets.tid(), term()) :: :ok | {:error, :table_not_found}

Safe ETS delete by key. Returns :ok or {:error, :table_not_found}.

safe_delete_table(table)

@spec safe_delete_table(atom() | :ets.tid()) :: :ok | {:error, :table_not_found}

Safe ETS table deletion. Returns :ok or {:error, :table_not_found}.

safe_insert(table, data)

@spec safe_insert(atom() | :ets.tid(), tuple() | [tuple()]) ::
  :ok | {:error, :table_not_found}

Safe ETS insert. Returns :ok or {:error, :table_not_found}.

safe_lookup(table, key)

@spec safe_lookup(atom() | :ets.tid(), term()) ::
  {:ok, list()} | {:error, :table_not_found}

Safe ETS lookup. Returns {:ok, rows} or {:error, :table_not_found}.