AttractorExPhx.PubSub (attractor_phoenix v0.1.0)

Copy Markdown View Source

Phoenix PubSub bridge for AttractorEx pipeline updates.

This module gives Phoenix applications a push-oriented integration path on top of the HTTP manager:

  • server-side processes and LiveViews can subscribe with subscribe_pipeline/2
  • browser clients can consume the same updates through a Phoenix Channel

Subscriptions are organized by per-pipeline topics. The bridge keeps a single manager subscription for each pipeline and republishes updates onto Phoenix PubSub as plain Elixir messages:

{:attractor_ex_event, event_map}

subscribe_pipeline/2 returns a snapshot so the caller can render initial state immediately before incremental events arrive.

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts the PubSub bridge.

Subscribes the current process to a pipeline topic and returns its current snapshot.

Returns the Phoenix PubSub topic name for a pipeline.

Unsubscribes the current process from a pipeline topic.

Types

snapshot()

@type snapshot() :: map()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

Starts the PubSub bridge.

subscribe_pipeline(pipeline_id, opts \\ [])

@spec subscribe_pipeline(
  String.t(),
  keyword()
) :: {:ok, snapshot()} | {:error, term()}

Subscribes the current process to a pipeline topic and returns its current snapshot.

topic(pipeline_id)

@spec topic(String.t()) :: String.t()

Returns the Phoenix PubSub topic name for a pipeline.

unsubscribe_pipeline(pipeline_id, opts \\ [])

@spec unsubscribe_pipeline(
  String.t(),
  keyword()
) :: :ok

Unsubscribes the current process from a pipeline topic.