Raxol.Core.Utils.GenServerHelpers (Raxol v2.0.1)

View Source

Common GenServer patterns and utilities to reduce code duplication. Provides standardized handlers for common operations like state retrieval, metrics collection, and configuration management.

Summary

Functions

Standard handler for getting specific state fields.

Standard handler for getting metrics from state.

Standard handler for getting state information.

Standard handler for getting status information.

Standard handler for resetting metrics.

Standard handler for updating configuration.

Utility to increment a metric counter.

Initialize default state with common fields.

Utility to update a metric value.

Functions

handle_get_field(field, state)

@spec handle_get_field(atom(), map()) :: {:reply, any(), map()}

Standard handler for getting specific state fields.

handle_get_metrics(state)

@spec handle_get_metrics(map()) :: {:reply, map(), map()}

Standard handler for getting metrics from state.

handle_get_state(state)

@spec handle_get_state(any()) :: {:reply, any(), any()}

Standard handler for getting state information.

handle_get_status(state)

@spec handle_get_status(map()) :: {:reply, map(), map()}

Standard handler for getting status information.

handle_reset_metrics(state)

@spec handle_reset_metrics(map()) :: {:reply, :ok, map()}

Standard handler for resetting metrics.

handle_update_config(new_config, state)

@spec handle_update_config(map(), map()) :: {:reply, :ok | {:error, any()}, map()}

Standard handler for updating configuration.

increment_metric(state, metric_name, amount \\ 1)

@spec increment_metric(map(), atom(), non_neg_integer()) :: map()

Utility to increment a metric counter.

init_default_state(custom_state \\ %{})

@spec init_default_state(map()) :: map()

Initialize default state with common fields.

update_metric(state, metric_name, value)

@spec update_metric(map(), atom(), any()) :: map()

Utility to update a metric value.