Pixir.Events (pixir v0.1.0)

Copy Markdown View Source

The event bus facade (ADR 0004, decision D-06): the seam between the core and every front-end. Front-ends subscribe; the core publishes. A renderer is just a subscriber that pattern-matches on event.type.

Dispatch is backed by a Registry (keys: :duplicate) keyed by session_id. Callers never touch the Registry directly — only this module. When web/multi-node support arrives, the backend swaps to Phoenix.PubSub behind the same API.

Subscribers receive messages shaped as {:pixir_event, event} where event is a Pixir.Event map.

Summary

Functions

Publish an Event to every subscriber of its session_id. Returns the event so it can be threaded (e.g. logged after publishing). Fan-out only — persistence is the Session's responsibility (canonical events go to the Log).

Child spec for the backing Registry (added to the supervision tree).

Subscribe the calling process to a Session's events. Delivered as {:pixir_event, %Pixir.Event{}} messages.

Number of live subscribers for a Session (mostly for tests/diagnostics).

Unsubscribe the calling process from a Session's events.

Functions

publish(event)

@spec publish(Pixir.Event.t()) :: Pixir.Event.t()

Publish an Event to every subscriber of its session_id. Returns the event so it can be threaded (e.g. logged after publishing). Fan-out only — persistence is the Session's responsibility (canonical events go to the Log).

registry_child_spec()

@spec registry_child_spec() :: Supervisor.child_spec()

Child spec for the backing Registry (added to the supervision tree).

subscribe(session_id)

@spec subscribe(String.t()) :: :ok

Subscribe the calling process to a Session's events. Delivered as {:pixir_event, %Pixir.Event{}} messages.

subscriber_count(session_id)

@spec subscriber_count(String.t()) :: non_neg_integer()

Number of live subscribers for a Session (mostly for tests/diagnostics).

unsubscribe(session_id)

@spec unsubscribe(String.t()) :: :ok

Unsubscribe the calling process from a Session's events.