0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 04:10:24 +00:00

Use cowboy_req:stream_events in the eventsource example

This commit is contained in:
Loïc Hoguin 2018-06-27 13:50:37 +02:00
parent 0fb68ec07f
commit 6b1db885d1
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764

View file

@ -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}.