From 8459bebceb9533948193774371cbd9fd571b78ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 16 Oct 2019 09:48:31 +0200 Subject: Cowboy 2.7.0 --- docs/en/cowboy/2.3/guide/loop_handlers/index.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'docs/en/cowboy/2.3/guide/loop_handlers/index.html') diff --git a/docs/en/cowboy/2.3/guide/loop_handlers/index.html b/docs/en/cowboy/2.3/guide/loop_handlers/index.html index 5e855b4f..a0507b84 100644 --- a/docs/en/cowboy/2.3/guide/loop_handlers/index.html +++ b/docs/en/cowboy/2.3/guide/loop_handlers/index.html @@ -70,7 +70,7 @@

Initialization

The init/2 function must return a cowboy_loop tuple to enable loop handler behavior. This tuple may optionally contain a timeout value and/or the atom hibernate to make the process enter hibernation until a message is received.

This snippet enables the loop handler:

-
@@ -78,7 +78,7 @@ http://www.gnu.org/software/src-highlite --> {cowboy_loop, Req, State}.

This also makes the process hibernate:

-
@@ -88,7 +88,7 @@ http://www.gnu.org/software/src-highlite -->

Receive loop

Once initialized, Cowboy will wait for messages to arrive in the process' mailbox. When a message arrives, Cowboy calls the info/3 function with the message, the Req object and the handler's state.

The following snippet sends a reply when it receives a reply message from another process, or waits for another message otherwise.

-
@@ -106,7 +106,7 @@ http://www.gnu.org/software/src-highlite -->

Streaming loop

Another common case well suited for loop handlers is streaming data received in the form of Erlang messages. This can be done by initiating a chunked reply in the init/2 callback and then using cowboy_req:chunk/2 every time a message is received.

The following snippet does exactly that. As you can see a chunk is sent every time an event message is received, and the loop is stopped by sending an eof message.

-
@@ -184,6 +184,8 @@ http://www.gnu.org/software/src-highlite --> +
  • 2.7
  • +
  • 2.6
  • 2.5
  • -- cgit v1.2.3