-
-
Save tlvenn/0e2e5785e7b7039c61525f407d357abe to your computer and use it in GitHub Desktop.
This file contains 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
def index(conn, %{"event" => "true"}) do | |
conn = conn | |
|> put_resp_content_type("text/event-stream") | |
|> send_chunked(200) | |
{:ok, conn} = chunk(conn, ["data: ", JSON.encode!(Thermostat.Data.get()), "\n\n"]) | |
Phoenix.Topic.subscribe self, "data" | |
data_updated(conn) | |
end | |
defp data_updated(conn) do | |
receive do | |
{ :update, data } -> | |
IO.puts "GOT DATA" | |
{:ok, conn} = chunk(conn, ["data: ", JSON.encode!(data), "\n\n"]) | |
_ -> | |
end | |
data_updated(conn) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment