I have an app where 2 people chat. But before they chat, BOTH parties have to press "accept"
on the front end I have a button that calls this function:
function acceptMatch() {
channel.push("accept_match", {
"matched_client_email": matchedClientEmail,
});
}
in my phoenix channel I have this (which is incomplete because I'm not sure what to do):
def handle_in("accept_match", %{ "matched_client_email" => matched_client_email }, socket) do
Logger.info "accept_match"
...
############################### here ####################################
match_accepted = true # <-- I want to be able to find out if the other person has pressed "accept" as well
case match_accepted do
true ->
...
{:noreply, socket}
_ ->
{:noreply, socket}
end
end
I looked into Agent, but that seems to be tied to a PID, which I wouldn't be able to easily pass around to different sockets. I'm trying to look for a common storage (other than a database) between all connections that I can save to / query. This way if party A presses accept, I can ask the storage "did party B accept?"
=== UPDATE ===
When I try using a named Agent I get this:
iex(11)> myfunc = fn -> %{} end
#Function<20.52032458/0 in :erl_eval.expr/5>
iex(12)> Agent.start_link(myfunc, name: "Cool")
** (CaseClauseError) no case clause matching: {"Cool", []}
(elixir) lib/gen_server.ex:544: GenServer.do_start/4
iex(12)>