Macaw.Live.Notify behaviour (macaw_live v0.1.0)

Copy Markdown View Source

The notification transport (spec/03 §7), a behavior over an argument (macaw 00 goal 3): how a page hears "this source's data changed; re-read it", and how the runtime's own broadcasts travel.

A host chooses it with the supervisor's notify: option, {module, arg}. Topics are prefixed by the supervisor's name, so two hosts sharing a PubSub never hear each other: "macaw:<live>:source:<name>" and "macaw:<live>:shared:<digest>" (topic/3). Each source manager (macaw_data's Macaw.Data.Manager) subscribes, when it starts, to the topic of its source's name (spec/03 §7); a notification is {:macaw_data, :changed, name, what} on it, what a change notice's (Macaw.Live.notify/3).

Summary

Callbacks

Sends message to every process subscribed to topic.

Subscribes the calling process to topic.

Unsubscribes the calling process from topic.

Functions

A topic of the supervisor live, by kind (:source or :shared) and name.

Callbacks

broadcast(arg, topic, message)

@callback broadcast(arg :: term(), topic :: String.t(), message :: term()) ::
  :ok | {:error, term()}

Sends message to every process subscribed to topic.

subscribe(arg, topic)

@callback subscribe(arg :: term(), topic :: String.t()) :: :ok | {:error, term()}

Subscribes the calling process to topic.

unsubscribe(arg, topic)

@callback unsubscribe(arg :: term(), topic :: String.t()) :: :ok

Unsubscribes the calling process from topic.

Functions

topic(live, kind, name)

@spec topic(atom(), :source | :shared, String.t()) :: String.t()

A topic of the supervisor live, by kind (:source or :shared) and name.

iex> Macaw.Live.Notify.topic(MyApp.Macaw, :source, "services")
"macaw:MyApp.Macaw:source:services"