diff options
Diffstat (limited to 'docs/en/cowboy/2.0/guide/loop_handlers.asciidoc')
-rw-r--r-- | docs/en/cowboy/2.0/guide/loop_handlers.asciidoc | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/docs/en/cowboy/2.0/guide/loop_handlers.asciidoc b/docs/en/cowboy/2.0/guide/loop_handlers.asciidoc index 58c42233..c0195ea0 100644 --- a/docs/en/cowboy/2.0/guide/loop_handlers.asciidoc +++ b/docs/en/cowboy/2.0/guide/loop_handlers.asciidoc @@ -1,6 +1,8 @@ [[loop_handlers]] == Loop handlers +// @todo This description needs to be updated. + Loop handlers are a special kind of HTTP handlers used when the response can not be sent right away. The handler enters instead a receive loop waiting for the right message before it can send @@ -36,8 +38,8 @@ This snippet enables the loop handler. [source,erlang] ---- -init(Req, _Opts) -> - {cowboy_loop, Req, #state{}}. +init(Req, State) -> + {cowboy_loop, Req, State}. ---- However it is largely recommended that you set a timeout @@ -46,8 +48,8 @@ also makes the process hibernate. [source,erlang] ---- -init(Req, _Opts) -> - {cowboy_loop, Req, #state{}, 30000, hibernate}. +init(Req, State) -> + {cowboy_loop, Req, State, 30000, hibernate}. ---- === Receive loop @@ -64,8 +66,8 @@ message otherwise. [source,erlang] ---- info({reply, Body}, Req, State) -> - Req2 = cowboy_req:reply(200, [], Body, Req), - {stop, Req2, State}; + cowboy_req:reply(200, [], Body, Req), + {stop, Req, State}; info(_Msg, Req, State) -> {ok, Req, State, hibernate}. ---- @@ -99,9 +101,9 @@ and the loop is stopped by sending an `eof` message. [source,erlang] ---- -init(Req, _Opts) -> +init(Req, State) -> Req2 = cowboy_req:chunked_reply(200, [], Req), - {cowboy_loop, Req2, #state{}}. + {cowboy_loop, Req2, State}. info(eof, Req, State) -> {stop, Req, State}; |