diff options
-rw-r--r-- | talks/tale-of-2.0-cowboy/index.html | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/talks/tale-of-2.0-cowboy/index.html b/talks/tale-of-2.0-cowboy/index.html index 3e4377d8..4861dd89 100644 --- a/talks/tale-of-2.0-cowboy/index.html +++ b/talks/tale-of-2.0-cowboy/index.html @@ -132,6 +132,20 @@ <li>Cowboy 2.1+ Websocket handlers</li> </ul> </section> + + <section> + <pre><code data-trim data-noescape> +init(StreamID, Req, Opts) → {Commands, State} + +data(StreamID, IsFin, Data, State) → {Commands, State} + +info(StreamID, Msg, State) → {Commands, State} + +terminate(StreamID, Reason, State) → _ + +early_error(StreamID, Reason, PartialReq, Resp, Opts) → Resp + </code></pre> + </section> </section> <section> @@ -143,9 +157,9 @@ <section> <pre><code data-trim data-noescape> #{ - middlewares => + middlewares ⇒ [cowboy_router, cowboy_handler], - stream_handlers => + stream_handlers ⇒ [cowboy_compress_h, cowboy_stream_h] } </code></pre> @@ -154,11 +168,11 @@ <section> <h3>Middleware</h3> <pre><code data-trim data-noescape> - execute(Req0, Env0) -> + execute(Req0, Env0) → case do_something(Req0, Env0) of - {ok, Req, Env} -> + {ok, Req, Env} → {ok, Req, Env}; - error -> + error → {stop, Req0} end. </code></pre> @@ -167,7 +181,7 @@ <section> <h3>Stream handler 1/2</h3> <pre><code data-trim data-noescape> -data(StreamID, IsFin, Data, State=#state{next=Next0}) -> +data(StreamID, IsFin, Data, State=#state{next=Next0}) → {Commands0, Next} = cowboy_stream:data( StreamID, IsFin, Data, Next0), fold(Commands0, State#state{next=Next}). @@ -177,7 +191,7 @@ data(StreamID, IsFin, Data, State=#state{next=Next0}) -> <section> <h3>Stream handler 2/2</h3> <pre><code data-trim data-noescape> -data(StreamID, IsFin, Data0, State=#state{next=Next0}) -> +data(StreamID, IsFin, Data0, State=#state{next=Next0}) → Data = do_something(Data0), {Commands0, Next} = cowboy_stream:data( StreamID, IsFin, Data, Next0), @@ -194,9 +208,9 @@ data(StreamID, IsFin, Data0, State=#state{next=Next0}) -> <section> <pre><code data-trim data-noescape> - loop() -> + loop() → receive - Msg -> + Msg → do_something(Msg), loop() end. @@ -240,16 +254,16 @@ Reason = <section> <pre><code data-trim data-noescape> -uri(Req :: cowboy_req:req()) -> uri(Req, #{}) -uri(Req :: cowboy_req:req(), Opts) -> URI :: iodata() +uri(Req :: cowboy_req:req()) → uri(Req, #{}) +uri(Req :: cowboy_req:req(), Opts) → URI :: iodata() Opts :: #{ - scheme => iodata() | undefined, - host => iodata() | undefined, - port => inet:port_number() | undefined, - path => iodata() | undefined, - qs => iodata() | undefined, - fragment => iodata() | undefined + scheme ⇒ iodata() | undefined, + host ⇒ iodata() | undefined, + port ⇒ inet:port_number() | undefined, + path ⇒ iodata() | undefined, + qs ⇒ iodata() | undefined, + fragment ⇒ iodata() | undefined } </code></pre> </section> @@ -257,16 +271,16 @@ Opts :: #{ <section> <pre><code data-trim data-noescape> read_body(Req :: cowboy_req:req()) - -> read_body(Req, #{}) + → read_body(Req, #{}) read_body(Req :: cowboy_req:req(), Opts) - -> {ok, Data :: binary(), Req} - | {more, Data :: binary(), Req} + → {ok, Data :: binary(), Req} + | {more, Data :: binary(), Req} Opts :: #{ - length => non_neg_integer(), - period => non_neg_integer(), - timeout => timeout() + length ⇒ non_neg_integer(), + period ⇒ non_neg_integer(), + timeout ⇒ timeout() } </code></pre> </section> |