Skip to content

Instantly share code, notes, and snippets.

@tslim
Last active June 6, 2020 08:00
Show Gist options
  • Save tslim/92f5dec7219299ca9a9e7be0283d27e9 to your computer and use it in GitHub Desktop.
Save tslim/92f5dec7219299ca9a9e7be0283d27e9 to your computer and use it in GitHub Desktop.
def mount(_params, session, socket) do
{:ok,
socket
|> subscribe_to_pubsub()
...
end
def handle_info(_message, socket) do
{:noreply, fetch_users(socket)}
end
defp subscribe_to_pubsub(socket) do
if connected?(socket), do: PubSub.subscribe(MyApp.PubSub, "topic_name")
socket
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment