janestreet / async

Jane Street Capital's asynchronous execution library
MIT License
205 stars 19 forks source link

Use libuv #17

Closed ORESoftware closed 11 months ago

ORESoftware commented 5 years ago

I am sure someone has considered this before, but why doesn't OCaml tap into Libuv, the same library that Node.js uses for Async I/O?

https://github.com/libuv/libuv

ghost commented 5 years ago

It's probably for historical reasons. I don't know how old libuv is but it's possible that it didn't exist when async started or that async developers were not aware of it at the time. At this point, porting async to use libuv would probably be a lot of work. That said, if you are interested or know someone who would be interested in working on this, we are happy to discuss it.

ORESoftware commented 5 years ago

@diml that makes sense...Libuv is battle-tested now and an excellent piece of software that Node.js has been depending on for 7 years now.

https://github.com/fdopen/uwt

the above is an effort to bind OCaml to Libuv. I am not sure if it works though, because I am just starting to learn OCaml, but I am a Node.js expert.

My current guess is that using async i/o calls with Libuv would be an alternative to the async library you have here, but they be able to be used together. Looks like that library uses lwt threading, and lwt and async are competitive libraries?

ghost commented 5 years ago

Yh it seems that uwt is for lwt which is an alternative to async. There several choices: you can either have an async_libuv library that exposes libuv functionalities to async programs or reimplement the primitives of async to use libuv. The former might be easier, though anything using async would have to migrate in order to benefit it.

aantron commented 4 years ago

This should be potentially more feasible with https://github.com/aantron/luv.

seliopou commented 4 years ago

I don't think this is something that we would want to take up in the short-term, as we're pretty happy with our current setup using epoll(7) directly. However, there probably should be a way to programmatically configure async to use a File_descr_watcher that doesn't come the async library itself. At that point your libuv could replace the event loop and you could use other libuv-related bindings as you see fit.

The problem is that right now File_descr_watchers you can use with async are limited by this type. We could introduce another type that you pass the creation/start functions of the schedule in order to provide a custom implementation of a watcher. Then libuv is hooked in and you're good to go.