Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions example/5-promise/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ For example, `let%lwt` is equivalent to...

We will stick to `let%lwt` in the examples and keep things tidy.

> [!NOTE]
> You may be wondering if the `let%lwt`, `try%lwt`, etc. constructs are really
> needed here. If you remove them, the example may appear to work the same way.
> However, this is not true for two reasons:
> Firstly, `let%lwt` awaits the computation before evaluating the next expression.
> Just `let response = ...` causes a race condition: `inner_handler` is started but
> not awaited and might access `successful` before or after it is incremented.
> Secondly, we are raising a normal exception with `raise`. If the handler happened
> to return a rejected promise instead of raising, we would have observed incorrect
> results. Therefore, it is safer to use the Lwt constructs in Dream handlers and
> middlewares to ensure all errors are handled correctly.

<br>

**Next steps:**
Expand Down
Loading