Conversation
src/bin/connect.ml
Outdated
| begin match Connection_limit.register description with | ||
| | Error (`Msg m) -> Lwt.fail_with m | ||
| | Ok idx -> |
There was a problem hiding this comment.
This looks a bit like Lwt_result.get_exn but specialised for the Msg case -- https://ocsigen.org/lwt/latest/api/Lwt_result
Perhaps define a quick operator for that and use it in all the places you do the Error -> Lwt.fail_with conversion?
There was a problem hiding this comment.
I added a
let ( >>*= ) m f = m >>= function
| Error (`Msg m) -> Lwt.fail_with m
| Ok x -> f xand used it in a bunch of places.
53de0ab to
62379e2
Compare
Both `Uwt` and `Luv` are bindings to `libuv`. `Uwt` hasn't been worked on in 3 years see fdopen/uwt#5 whereas `Luv` is under active development, and will probably become the IO foundation for `Lwt`, the promises library that we use. Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
The unit tests are run with `dune test` and should not need the network, so should work in sandboxed environments. The e2e tests are run with `dune build @e2e` and require the network and the ability to increase resource limits. Signed-off-by: David Scott <dave@recoil.org>
avsm
left a comment
There was a problem hiding this comment.
LGTM; just a minor question about clarifying watch (and the associated Lwt.async when calling it). Will be more important when porting to eio.
| type watch | ||
|
|
||
| val watch: ?path:string -> unit -> (watch, [ `Msg of string ]) result | ||
| val watch: ?path:string -> unit -> (watch, [ `Msg of string ]) result Lwt.t |
There was a problem hiding this comment.
Not quite clear what the Lwt.t here does. Does it block until the watching begins, or does it block indefinitely until the watch terminates?
There was a problem hiding this comment.
It blocks until the watching begins. I should clarify that in a doc, as it's not very obvious.
Signed-off-by: David Scott <dave@recoil.org>
Both Uwt and Luv are bindings to libuv, the scalable IO library used by node.js.
Advantages of
Uwt:Lwt-based API for promises so works easily with the rest of our codeDisadvantages of
Uwt:Advantages of
Luv:Lwtin future (LuvandLwthave the same maintainers)duneso will help us remove Cygwin, fix our Windows build and vendor our dependenciesDisadvantages of
Luv:libuvso we need to carefully interface with theLwtevent loopvpnkithad already separated out IO into a separate module, which was needed to migrate fromLwt_unixtoUwtin the past. However theLuvinterface is a thinner layer on top oflibuvwhich means we need to carefully interface thelibuvcallback-based world with theLwtpromise world. The proposal here is to runLuvon one thread andLwton another, and to use Mutex-protected Queues to send work between the two event loops.A typical function which can be called from
Lwtlooks like this:where
Luv_lwt.in_luvpushes the function to a queue and signals theLuvevent loop, and then when a return result is finally ready, the functionreturnpushes the value to a queue and signals theLwtevent loop. The queues and signalling is all in a small module Luv_lwt.The callback code is bit nested in places in this style:
see for example binding a UDP socket (you have to expand the collapsed diff of
host.mlotherwise it's not visible).but I thought I'd write everything out before trying to be too clever with combinators.
This was a good opportunity to start writing some inline unit tests to complement the existing end-to-end tests.
It was also a good opportunity to reformat the new code with
ocamlformat.Signed-off-by: David Scott dave@recoil.org