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