Raxol.Core.Runtime.Events.Handlers (Raxol v0.3.0)

View Source

Manages event handlers registration and execution in the Raxol system.

This module is responsible for:

  • Registering event handlers for specific event types
  • Executing handlers when events occur
  • Managing the priority and order of handlers

Summary

Functions

Executes all registered handlers for the given event.

Registers a new event handler for the specified event types.

Unregisters an event handler.

Functions

execute_handlers(event, state)

Executes all registered handlers for the given event.

Handlers are executed in priority order (lowest to highest). Each handler can transform the event for the next handler.

Parameters

  • event: The event to handle
  • state: The current application state

Returns

{:ok, updated_event, updated_state} if all handlers executed successfully, {:error, reason, state} if a handler failed.

register_handler(handler_id, event_types, handler_fun, options \\ [])

Registers a new event handler for the specified event types.

Parameters

  • handler_id: Unique identifier for the handler
  • event_types: List of event types the handler should receive
  • handler_fun: Function to call when an event occurs
  • options: Additional options for handler registration
    • :priority - Handler priority (default: 100, lower numbers run first)
    • :filter - Optional filter function to determine if events should be handled

Returns

{:ok, handler_id} if registration succeeded, {:error, reason} otherwise.

unregister_handler(handler_id)

Unregisters an event handler.

Parameters

  • handler_id: ID of the handler to remove

Returns

:ok if the handler was removed, {:error, :not_found} if the handler wasn't registered.