mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Document loop handlers in the guide
This commit is contained in:
parent
09c68ca755
commit
a27296b34d
2 changed files with 14 additions and 7 deletions
|
@ -16,15 +16,23 @@ While the same can be accomplished using plain HTTP handlers,
|
|||
it is recommended to use loop handlers because they are well-tested
|
||||
and allow using built-in features like hibernation and timeouts.
|
||||
|
||||
Callbacks
|
||||
---------
|
||||
|
||||
@todo Describe the callbacks.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
@todo Explain how to use them.
|
||||
Loop handlers are used for requests where a response might not
|
||||
be immediately available, but where you would like to keep the
|
||||
connection open for a while in case the response arrives. The
|
||||
most known example of such practice is known as long-polling.
|
||||
|
||||
Loop handlers can also be used for requests where a response is
|
||||
partially available and you need to stream the response body
|
||||
while the connection is open. The most known example of such
|
||||
practice is known as server-sent events.
|
||||
|
||||
Loop handlers essentially wait for one or more Erlang messages
|
||||
and feed these messages to the `info/3` callback. It also features
|
||||
the `init/3` and `terminate/2` callbacks which work the same as
|
||||
for plain HTTP handlers.
|
||||
|
||||
The following handler waits for a message `{reply, Body}` before
|
||||
sending a response. If this message doesn't arrive within 60
|
||||
|
|
|
@ -21,7 +21,6 @@ Cowboy User Guide
|
|||
* Usage
|
||||
* [Loop handlers](loop_handlers.md)
|
||||
* Purpose
|
||||
* Callbacks
|
||||
* Usage
|
||||
* [Websocket handlers](ws_handlers.md)
|
||||
* Purpose
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue