Browse Source

Use cowboy_req:stream_events in the eventsource example

Loïc Hoguin 7 years ago
parent
commit
6b1db885d1
1 changed files with 4 additions and 1 deletions
  1. 4 1
      examples/eventsource/src/eventsource_handler.erl

+ 4 - 1
examples/eventsource/src/eventsource_handler.erl

@@ -14,7 +14,10 @@ init(Req0, Opts) ->
 	{cowboy_loop, Req, Opts}.
 
 info({message, Msg}, Req, State) ->
-	cowboy_req:stream_body(["id: ", id(), "\ndata: ", Msg, "\n\n"], nofin, Req),
+	cowboy_req:stream_events(#{
+		id => id(),
+		data => Msg
+	}, nofin, Req),
 	erlang:send_after(1000, self(), {message, "Tick"}),
 	{ok, Req, State}.