Hub (hub v1.0.1)
Pub-sub hub
Subscription is done with a pattern.
Example:
Hub.subscribe("global", %{count: count} when count > 42)
Hub.publish("global", %{count: 45, message: "You rock!"})
Link to this section Summary
Functions
Publishes the term to all subscribers that matches it. Returns the number of subscribers that got the message.
Convenience macro for subscribing without the need to unquote the pattern.
Subscribes to the quoted pattern in the given channel_name.
Get all subscribers from channel.
Unsubscribes using the reference returned on subscribe.
Link to this section Functions
Link to this function
publish(channel_name, term)
Specs
publish(String.t(), any()) :: non_neg_integer()
Publishes the term to all subscribers that matches it. Returns the number of subscribers that got the message.
Convenience macro for subscribing without the need to unquote the pattern.
Example:
Hub.subscribe("global", %{count: count} when count > 42)
Link to this function
subscribe_quoted(channel_name, quoted_pattern, options \\ [])
Specs
subscribe_quoted(String.t(), any(), Hub.Channel.subscribe_options()) :: {:ok, Hub.Channel.subscription_ref()} | {:error, reason :: String.t()}
Subscribes to the quoted pattern in the given channel_name.
Example:
Hub.subscribe("global", quote do: %{count: count} when count > 42)
Link to this function
subscribers(channel_name)
Specs
subscribers(String.t()) :: [Hub.Subscriber.t()]
Get all subscribers from channel.
Link to this function
unsubscribe(ref)
Unsubscribes using the reference returned on subscribe.
Link to this function