Skip to content

Tutorial 5-promise does not support its rationale/might be deprecated #389

@pierre-ludmann-depinfonancy

Description

Hi!

I was going through the tutorial exemples to discover Dream and I keep thinking about 5-promise. Its rationale is to able computation after inner handling of the request; while previous example was limited to computation beforehand. It conveys the idea this is thanks to Lwt. Here is a trace log from the current example:

% dune exec --root . ./promise.exe
12.04.25 01:28:52.717                       Running at http://localhost:8080
12.04.25 01:28:52.717                       Type Ctrl+C to stop
12.04.25 01:28:56.081    dream.logger  INFO REQ 1 GET / ::1:55144 fd 8 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
12.04.25 01:28:56.081    dream.logger  INFO REQ 1 200 in 128 μs
12.04.25 01:28:57.324    dream.logger  INFO REQ 2 GET / ::1:55144 fd 8 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
12.04.25 01:28:57.324    dream.logger  INFO REQ 2 200 in 193 μs
12.04.25 01:29:01.223    dream.logger  INFO REQ 3 GET / ::1:55144 fd 8 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
12.04.25 01:29:01.224    dream.logger  INFO REQ 3 200 in 111 μs
12.04.25 01:29:04.895    dream.logger  INFO REQ 4 GET /fail ::1:55144 fd 8 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
12.04.25 01:29:04.895    dream.logger  WARN REQ 4 Aborted by: Failure("The Web app failed!")
12.04.25 01:29:04.895    dream.logger  WARN Raised at Dune__exe__Promise.count_requests.(fun) in file "promise.ml", line 12, characters 4-13
12.04.25 01:29:04.895    dream.logger  WARN Called from Lwt.Sequence_associated_storage.with_value in file "src/core/lwt.ml", line 804, characters 19-23
12.04.25 01:29:04.895    dream.logger  WARN Re-raised at Lwt.Sequence_associated_storage.with_value in file "src/core/lwt.ml", line 809, characters 6-15
12.04.25 01:29:04.895    dream.logger  WARN Called from Lwt.Sequential_composition.try_bind in file "src/core/lwt.ml", line 2139, characters 10-14
12.04.25 01:29:04.895      dream.http ERROR REQ 4 Failure("The Web app failed!")
12.04.25 01:29:04.895      dream.http ERROR REQ 4 Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
12.04.25 01:29:04.895      dream.http ERROR REQ 4 Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
12.04.25 01:29:07.056    dream.logger  INFO REQ 5 GET / ::1:55144 fd 8 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
12.04.25 01:29:07.057    dream.logger  INFO REQ 5 200 in 134 μs

However, when I remove Lwt, the behavior is the same (save for some ERROR logs):

% git diff promise.ml             
diff --git a/example/5-promise/promise.ml b/example/5-promise/promise.ml
index ffa2790..bebfea3 100644
--- a/example/5-promise/promise.ml
+++ b/example/5-promise/promise.ml
@@ -2,10 +2,10 @@ let successful = ref 0
 let failed = ref 0
 
 let count_requests inner_handler request =
-  try%lwt
-    let%lwt response = inner_handler request in
+  try
+    let response = inner_handler request in
     successful := !successful + 1;
-    Lwt.return response
+    response
 
   with exn ->
     failed := !failed + 1;
% dune exec --root . ./promise.exe
12.04.25 01:31:42.248                       Running at http://localhost:8080
12.04.25 01:31:42.248                       Type Ctrl+C to stop
12.04.25 01:31:50.938    dream.logger  INFO REQ 1 GET / ::1:55152 fd 8 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
12.04.25 01:31:50.938    dream.logger  INFO REQ 1 200 in 89 μs
12.04.25 01:31:52.675    dream.logger  INFO REQ 2 GET / ::1:55152 fd 8 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
12.04.25 01:31:52.675    dream.logger  INFO REQ 2 200 in 79 μs
12.04.25 01:31:57.211    dream.logger  INFO REQ 3 GET / ::1:55152 fd 8 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
12.04.25 01:31:57.212    dream.logger  INFO REQ 3 200 in 397 μs
12.04.25 01:32:01.724    dream.logger  INFO REQ 4 GET /fail ::1:55152 fd 8 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
12.04.25 01:32:01.724    dream.logger  WARN REQ 4 Aborted by: Failure("The Web app failed!")
12.04.25 01:32:01.724    dream.logger  WARN Raised at Dune__exe__Promise.(fun) in file "promise.ml", line 22, characters 8-45
12.04.25 01:32:01.724    dream.logger  WARN Called from Dune__exe__Promise.count_requests in file "promise.ml", line 6, characters 19-40
12.04.25 01:32:01.724    dream.logger  WARN Re-raised at Dune__exe__Promise.count_requests in file "promise.ml", line 12, characters 4-13
12.04.25 01:32:01.724    dream.logger  WARN Called from Lwt.Sequence_associated_storage.with_value in file "src/core/lwt.ml", line 804, characters 19-23
12.04.25 01:32:01.725    dream.logger  WARN Re-raised at Lwt.Sequence_associated_storage.with_value in file "src/core/lwt.ml", line 809, characters 6-15
12.04.25 01:32:01.725    dream.logger  WARN Called from Lwt.Sequential_composition.try_bind in file "src/core/lwt.ml", line 2139, characters 10-14
12.04.25 01:32:01.725      dream.http ERROR REQ 4 Failure("The Web app failed!")
12.04.25 01:32:01.725      dream.http ERROR REQ 4 Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
12.04.25 01:32:01.725      dream.http ERROR REQ 4 Called from Logs.Tag.find in file "src/logs.ml", line 153, characters 14-32
12.04.25 01:32:04.631    dream.logger  INFO REQ 5 GET / ::1:55152 fd 8 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
12.04.25 01:32:04.631    dream.logger  INFO REQ 5 200 in 124 μs

As such, I feel misled by this tutorial example. Did that example deprecate? Am I daft and missing something entirely?

Thank you for reading and for the dream

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions