use >>= bind syntax

This commit is contained in:
Kaustubh Maske Patil 2025-05-08 12:20:40 +05:30
parent 2e4779cc96
commit 6444a022a5

View File

@ -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));