Best way to write non blocking in Ocaml 5

Completely new to Ocaml community and would like to know what libraries can be used to write non blocking networking code.

My background is Rust and Scala/ZIO.


1 Like

For now, the proven-in-production approach is using the Lwt library for cooperative non-blocking I/O with promises: Lwt manual

E.g. a popular web framework which uses Lwt: Dream — Tidy, feature-complete web framework

Lwt is designed to run on a single thread. So if you want to take advantage of multicore in OCaml 5+ you would probably need to start N domains (threads) each running its own copy of your overall Lwt program independently in parallel.

In the (hopefully) near future, a new concurrency library called Eio is expected (hoped) to take over the ecosystem: GitHub - ocaml-multicore/eio: Effects-based direct-style IO for multicore OCaml

Eio is designed to work seamlessly with multicore and can be used directly to start multiple domains and manage them using fibers (basically equivalent to ZIO ZIO#fork). Libraries or frameworks which use Eio need to be architected in such a way that they take advantage of this though. It won’t happen automatically.