let () = let timer = Luv.Timer.init () |> Stdlib.Result.get_ok in ignore (Luv.Timer.start timer 1000 (fun () -> print_endline "Hello, world!")); print_endline "Waiting..."; ignore (Luv.Loop.run ())
Luv exposes sockets, files, subprocesses, FS events, and many other OS APIs. Indeed, Luv is an independent alternative to the standard
Unix, and does not depend on
Unix. The easiest way to get an idea of all that is available is to quickly scroll through the list of modules in the API docs.
You are invited to glance through all of Luv’s documentation:
- Project page
- User guide
- API reference
- Examples, which are discussed in the guide…
- …and the documentation of libuv
libuv is focused primarily on event-driven programming, which makes it similar to Async or Lwt. However, it does not offer a promise data type — the API is written in terms of callbacks.
libuv also supports multithreading and multiprocessing. In particular, libuv allows running multiple event loops in multiple threads, which makes it a ready candidate for use with a multicore runtime.
Luv uses ctypes to greatly minimize the amount of C code in the repo. A thorough test suite checks return values, I/O effects, and interaction with the OCaml garbage collector and threading runtime. Luv vendors libuv to avoid version conflicts, and, when you install Luv, it automatically builds its internal libuv.
One of the main goals of Luv is to be easy to integrate into larger projects. For example, there may be an experimental version of Lwt based on it. To that end, Luv is as unopinionated as possible. It sticks closely to the libuv API, making no unnecessary design decisions, and deviating only where changes are necessary to integrate with OCaml, or where libuv has an awkward API due to the limitations of C.
And with all that… Happy systems programming