Introduction to Lwt

Hello,

I’ve published https://raphael-proust.github.io/code/lwt-part-1.html, a 2-part introduction to Lwt.

The main aim of the introduction is to give a good mental model of what promises are, how they behave and how to use them. It assumes basic familiarity with OCaml.

Don’t hesitate to ask questions or share feedback.

20 Likes

I had a long discussion about a very tiny bit of code and specifically about the yielding behaviour/execution order within the Lwt part of the code. So I made an small addendum to the tutorial:
https://raphael-proust.gitlab.io/code/lwt-part-3.html#addendum-non-obvious-evaluation-order

It highlights how the behaviours of bind and wakeup interact. It also waffles on a bit about how pause and run interact. The behaviours of all these functions were already described in the post. In that sense the addendum does not bring any new information. However, it does point out some emergent (and, some would say, surprising) behaviours when the functions are combined.

Anyone interested in the very minutia of scheduling might be interested in reading through the addendum.

5 Likes

Thank you for the article. Is it possible to add a section on how to unittest libraries that use Lwt? I haven’t seen any material on this online. I tried using Ounit2 but it appears that testing assert_raises never actually works and reports that the 'a Lwt.t returning function never raises the expected exception.

Thanks for the suggestion, it’d make a good addition! I can’t commit to any timeline on that, but I’ll look into adding it.

1 Like