0
我試圖分配頭像,但當我嘗試使用它時出現錯誤。如何在Phoenix中存儲內存中的變量?
我來自節點背景,在那裏我可以分配值,然後從請求中修改它們。我應該看看維護狀態?
defmodule Chatroom.LobbyChannel do
require Runner
use Phoenix.Channel
{:ok, pid: spawn(fn -> Runner.input() end)}
avatar = %{x: 0, y: 0}
def join("lobby", _payload, socket) do
{:ok, socket}
end
def handle_in("new_message", payload, socket) do
case payload["message"] do
"hello" -> broadcast! socket, "new_message", payload
"jump" -> send pid, {:jump, self, [avatar: avatar, socket: socket]}
_ -> nil
end
{:noreply, socket}
end
def handle_reply do
receive do
{:result, mover, socket} -> broadcast! socket, "new_message", [name: "State", message: "5"]
end
end
end
謝謝 - 我會在哪裏啓動我的代理?看起來start_link用於在使用它之前鏈接一個函數。鳳凰城的籌碼在哪裏? – quantumpotato
這取決於你的經紀人的生命週期。如果您需要它始終可用,請在主應用程序中將其作爲受監督員工啓動。 – mudasobwa