use >>= bind syntax
This commit is contained in:
parent
2e4779cc96
commit
6444a022a5
@ -1,3 +1,4 @@
|
|||||||
|
open Lwt.Infix
|
||||||
open Lwt.Syntax
|
open Lwt.Syntax
|
||||||
|
|
||||||
let successful = ref 0
|
let successful = ref 0
|
||||||
@ -6,9 +7,9 @@ let failed = ref 0
|
|||||||
(* middleware *)
|
(* middleware *)
|
||||||
let count_requests inner_handler request =
|
let count_requests inner_handler request =
|
||||||
try%lwt
|
try%lwt
|
||||||
let* response = inner_handler request in
|
(inner_handler request) >>= (fun response ->
|
||||||
successful := !successful + 1;
|
successful := !successful + 1;
|
||||||
Lwt.return response
|
Lwt.return response)
|
||||||
|
|
||||||
with exn ->
|
with exn ->
|
||||||
failed := !failed + 1;
|
failed := !failed + 1;
|
||||||
@ -23,6 +24,10 @@ let () =
|
|||||||
(fun _ ->
|
(fun _ ->
|
||||||
Dream.html "Hello, world!");
|
Dream.html "Hello, world!");
|
||||||
|
|
||||||
|
Dream.get "/error"
|
||||||
|
(fun _ ->
|
||||||
|
failwith "failed on purpose");
|
||||||
|
|
||||||
Dream.get "/count"
|
Dream.get "/count"
|
||||||
(fun _ ->
|
(fun _ ->
|
||||||
Dream.html (Printf.sprintf "%3i successful requests<br>%3i failed requests" !successful !failed));
|
Dream.html (Printf.sprintf "%3i successful requests<br>%3i failed requests" !successful !failed));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user