# Best way to write non blocking in Ocaml 5

**URL:** https://discuss.ocaml.org/t/best-way-to-write-non-blocking-in-ocaml-5/13039
**Category:** Learning
**Created:** [September 17, 2023, 3:32am UTC](https://discuss.ocaml.org/t/best-way-to-write-non-blocking-in-ocaml-5/13039 "2023-09-17T03:32:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![trickster](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/trickster/32/4700_2.png) [@trickster](https://discuss.ocaml.org/u/trickster)
#### Post date: [September 17, 2023, 3:32am UTC](https://discuss.ocaml.org/t/best-way-to-write-non-blocking-in-ocaml-5/13039/1 "2023-09-17T03:32:32Z")

</div>

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.

Thanks.

---

<div class="post-metadata">

### Author: ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)
#### Post date: [September 17, 2023, 3:46am UTC](https://discuss.ocaml.org/t/best-way-to-write-non-blocking-in-ocaml-5/13039/2 "2023-09-17T03:46:10Z")

</div>

For now, the proven-in-production approach is using the Lwt library for cooperative non-blocking I/O with promises: [Lwt manual](https://ocsigen.org/lwt/latest/manual/manual)

E.g. a popular web framework which uses Lwt: [Dream — Tidy, feature-complete web framework](https://aantron.github.io/dream/)

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](https://github.com/ocaml-multicore/eio)

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.
