Fledex.Utils.PubSub (fledex v0.7.0)

View Source

This module collects all functions that are about publish and subscribe (PubSub) functionality.

PubSub is used for 2 things (more things are likely to be added in the future):

  • Notifications related to triggers (when repaints happen). You can inject into this information flow by calling broadcast_trigger/1
  • Notifications related to state changes. Those are triggered mainly by effects, but also an animation can publish them. Fledex.Animation.Coordinators are the main consumer of those events to then take appopriate actions. Those events are published through broadcast_state/2

Summary

Functions

Use this function if you want to publish to the state channel

Use this function if you want to publish to the trigger channel

Name of the channel to which state events will be published. State events are those that are related to animations and effects and are important for coordinators.

Name of the channel to which trigger events will be published. Trigger events are those that are related to the redrawing of the led strip

Functions

broadcast(pubsub \\ Utils.pubsub_name(), topic, message)

See Phoenix.PubSub.broadcast/3.

broadcast_state(state, context)

@spec broadcast_state(any(), map()) :: :ok | {:error, term()}

Use this function if you want to publish to the state channel

See also the channel_state/0 for more informration.

broadcast_trigger(message)

@spec broadcast_trigger(map()) :: :ok | {:error, term()}

Use this function if you want to publish to the trigger channel

See also the channel_trigger/0 for more informration.

channel_state()

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

Name of the channel to which state events will be published. State events are those that are related to animations and effects and are important for coordinators.

channel_trigger()

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

Name of the channel to which trigger events will be published. Trigger events are those that are related to the redrawing of the led strip

direct_broadcast!(node, pubsub \\ Utils.pubsub_name(), topic, message)

See Phoenix.PubSub.direct_broadcast!/4.

subscribe(pubsub \\ Utils.pubsub_name(), topic)

See Phoenix.PubSub.subscribe/2.

unsubscribe(pubsub \\ Utils.pubsub_name(), topic)

See Phoenix.PubSub.unsubscribe/2.