pharos/event_bus
The alert event bus.
A thin, restart-resilient wrapper around an eparch/event_manager
configured with a registered name. The wrapper holds the Name, not
a Pid or Manager value, so handles stay valid across supervisor
restarts: when the underlying gen_event process is restarted under
the same registered name, every previously-issued EventBus handle
keeps working transparently.
Most callers should not interact with EventBus directly: it is
constructed by the pharos supervisor and exposed indirectly via
pharos.subscribe / pharos.unsubscribe.
Types
Values
pub fn add_handler(
bus: EventBus,
handler: fn(alert.AlertEvent) -> Nil,
) -> Result(HandlerId, event_manager.AddError(Nil, Nil))
Register a Gleam function as an event handler on the bus.
pub fn from_name(
name: process.Name(alert.AlertEvent),
) -> EventBus
Wrap a registered name as an EventBus. The name must already (or
eventually) be registered to a running gen_event manager process;
the wrapper resolves it lazily on every API call.
pub fn notify(bus: EventBus, event: alert.AlertEvent) -> Nil
Broadcast event to every registered handler. Non-blocking.
pub fn remove_handler(
bus: EventBus,
id: HandlerId,
) -> Result(Nil, event_manager.RemoveError(Nil, Nil))
Unregister a previously added handler.
pub fn start_link(
name: process.Name(alert.AlertEvent),
) -> Result(#(process.Pid, EventBus), event_manager.StartError)
Start a fresh event bus registered under name.
Used by the supervisor’s bus child. The returned Pid is the bus’s
process id (suitable for actor.Started); the bus is also registered
under name so other processes can reach it after a restart.