spizzy
I’m currently learning some phoenix and built a counting app with a simple increase/decrease. Both worked fine so I decided to implement GenServers and PubSub to see how many users currently are on the page (presence).
Whole error:
GenServer #PID<0.511.0> terminating
** (FunctionClauseError) no function clause matching in CounterWeb.Counter.handle_info/2
(counter 0.1.0) lib/counter_web/live/counter.ex:45: CounterWeb.Counter.handle_info({:count, 1}, #Phoenix.LiveView.Socket<assigns: %{__changed__: %{}, flash: %{}, live_action: nil, present: 1, val:
1}, endpoint: CounterWeb.Endpoint, id: "phx-FtSq5dehn8AlGgAF", parent_pid: nil, root_pid: #PID<0.511.0>, router: CounterWeb.Router, transport_pid: #PID<0.506.0>, view: CounterWeb.Counter, ...>)
I think it’s coming from my make change function
defp make_change(count, change) do
new_count = count + change
PubSub.broadcast(Counter.PubSub, topic(), {:count, new_count})
{:reply, new_count, new_count}
end
and my handle info
def handle_info(
%{event: "presence_diff", payload: %{joins: joins, leaves: leaves}},
%{assigns: %{present: present}} = socket
) do
new_present = present + map_size(joins) - map_size(leaves)
{:noreply, assign(socket, :present, new_present)}
end
Someone recommended me to create another clause and do the same kind of setup as I did with the previous functions to handle the calls, example:
def handle_call(:reply, _from, count) do
{:ok, count, count}
end
def handle_call(:incr, _from, count) do
make_change(count, +1)
end
def handle_call(:decr, _from, count) do
make_change(count, -1)
end
My first argument is the message I receive, I am sending a tuple and I have to match that tuple.
I think I have to add another handle_info, like this
def handle_info({count: count}, socket) do
# ???
{:noreply, socket}
end
How would I handle/implement that? Can anyone help me by explaining that a bit?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Hello
I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley:
Mutonex gamedesign was finish...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #elixirconf-us
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #security
- #elixirconf-eu
- #api
- #forms
- #performance










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kartheek
If you are getting function clause matching error - you have to add new handle_info/2
It should be like what is described in error message
{:count, count}not{count: count}I am little confused - you are speaking about GenServer and the error message and your sample code refers to PhoenixLiveView.Socket.
You have implemented the GenServer and Pubsub part and you want to handle the PubSub message in LiveView ?
spizzy
so just
kartheek
{:noreply, assign(socket, :val, count)}- did it work ?spizzy
I just had to add the following function to get it working, is there any better solution maybe?