A GenServer-based event emitter that allows subscribing to and emitting events.
Subscribers receive events asynchronously via spawned tasks.
Summary
Functions
Returns a specification to start this module under a supervisor.
Emits an event to all subscribers asynchronously.
Starts the EventEmitter GenServer.
Subscribes to an event type.
Unsubscribes from events using the reference returned by subscribe.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Emits an event to all subscribers asynchronously.
Parameters
pid- The EventEmitter processevent- The event struct to emit
Examples
EventEmitter.emit(emitter, %GoalSubmittedEvent{state: state})
Starts the EventEmitter GenServer.
Subscribes to an event type.
Returns a reference that can be used to unsubscribe.
Parameters
pid- The EventEmitter processevent_type- The event module to subscribe tocallback- Function to call when event is emitted
Examples
ref = EventEmitter.subscribe(emitter, GoalSubmittedEvent, fn event ->
IO.inspect(event)
end)
EventEmitter.unsubscribe(emitter, ref)
Unsubscribes from events using the reference returned by subscribe.