View Source ConfigCat.Hooks (ConfigCat v4.0.2)
Subscribe to events fired by the SDK.
Hooks are callback functions that are called by the SDK when certain events happen. Client applications can register more than one callback for each hook.
Callbacks are called within the same process that generated the event. Any
exceptions that are raised by a callback are rescued, logged, and reported to
any registered on_error
callbacks.
The following callbacks are available:
on_client_ready
: This event is sent when the SDK reaches the ready state. If the SDK is set up with lazy load or manual polling it's considered ready right after instantiation. If it's using auto polling, the ready state is reached when the SDK has a valid config JSON loaded into memory either from cache or from HTTP.on_config_changed(config: map())
: This event is sent when the SDK loads a valid config JSON into memory from cache, and each subsequent time when the loaded config JSON changes via HTTP.on_flag_evaluated(evaluation_details: EvaluationDetails.t())
: This event is sent each time when the SDK evaluates a feature flag or setting. The event sends the same evaluation details that you would get from get_value_details.- on_error(error: String.t()): This event is sent when an error occurs within the ConfigCat SDK.
Summary
Types
A hook callback is either an anonymous function or a module/function name/extra_arguments tuple.
Functions
Add an on_client_ready
callback.
Add an on_config_changed
callback.
Add an on_error
callback.
Add an on_flag_evaluated
callback.
Returns a specification to start this module under a supervisor.
Types
A hook callback is either an anonymous function or a module/function name/extra_arguments tuple.
Each callback is passed specific arguments. These specific arguments are prepended to the extra arguments provided in the tuple (if any).
For example, you might want to define a callback that sends a message to another process which the config changes. You can pass the pid of that process as an extra argument:
def MyModule do
def subscribe_to_config_changes(subscriber_pid) do
ConfigCat.hooks()
|> ConfigCat.Hooks.add_on_config_changed({__MODULE__, :on_config_changed, [subscriber_pid]})
end
def on_config_changed(config, pid) do
send pid, {:config_changed, config}
end
end
@type on_client_ready_callback() :: (-> any()) | named_callback()
@type on_config_changed_callback() :: (ConfigCat.Config.settings() -> any()) | named_callback()
@type on_error_callback() :: (String.t() -> any()) | named_callback()
@type on_flag_evaluated_callback() :: (ConfigCat.EvaluationDetails.t() -> any()) | named_callback()
@type option() :: {:on_client_ready, on_client_ready_callback()} | {:on_config_changed, on_config_changed_callback()} | {:on_error, on_error_callback()} | {:on_flag_evaluated, on_flag_evaluated_callback()}
@type start_option() :: {:hooks, t()} | {:instance_id, ConfigCat.instance_id()}
@opaque t()
Functions
@spec add_on_client_ready(t(), on_client_ready_callback()) :: t()
Add an on_client_ready
callback.
@spec add_on_config_changed(t(), on_config_changed_callback()) :: t()
Add an on_config_changed
callback.
@spec add_on_error(t(), on_error_callback()) :: t()
Add an on_error
callback.
@spec add_on_flag_evaluated(t(), on_flag_evaluated_callback()) :: t()
Add an on_flag_evaluated
callback.
Returns a specification to start this module under a supervisor.
See Supervisor
.