Last active
February 29, 2016 23:55
-
-
Save emschwar/fe630a4bc6d641fb3447 to your computer and use it in GitHub Desktop.
Hello Controller with redis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule HelloPhoenix.HelloController do | |
use HelloPhoenix.Web, :controller | |
def index(conn, _params) do | |
render conn, "index.html" | |
end | |
def show(conn, %{"messenger" => messenger} = params) do | |
HelloPhoenix.Endpoint.subscribe(self(), "potato") | |
receive do | |
%Phoenix.Socket.Broadcast{event: "response", payload: %{message: message}, topic: "potato"} -> | |
IO.puts "here's a message" | |
IO.inspect message | |
render conn, "show.html", messenger: messenger, message: message | |
after | |
120000 -> send_resp(conn, :no_content, "") | |
end | |
end | |
def create(conn, %{"message" => message} = params) do | |
HelloPhoenix.Endpoint.broadcast("potato", "response", %{message: message}) | |
send_resp(conn, :no_content, "") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment