Luv — cross-platform concurrent I/O: a binding to libuv

I am pleased to announce the first release of Luv, a binding to libuv. libuv is the cross-platform C library inside Node.js that does I/O, wraps system calls, and drives Node’s main loop.

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:


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.


A major advantage of libuv is that, because it is a core module of Node, it is well-maintained and supports many platforms. Luv inherits these properties.

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 :slight_smile:

43 Likes

I cannot like this hard enough. Thank you thank you thank you!

2 Likes

The name reminded me of luvit (see their GitHub repository).

2 Likes

Very nice. Thanks for this. :100:

1 Like

Love this. Thank you so much.

Will definitely be giving this a go. Would be neat, down the line, to see how it compares to Lwt and/or Async :slight_smile:

1 Like