If that turns up issues, I suppose one work-around, albeit sub-optimal, is to restore the effect of Lwt_unix.(set_default_async_method Async_none)
, and copiously document the need to call it if invoking anything in Lwt_process
or Lwt_unix.fork
and Lwt_unix.system
and so forth. But the best advice is probably not to try spawning new processes in any Lwt
program.
I think @raphael-proust 's answer is excellent, but Iād like to add a couple things:
- the implementation is roughly 130 loc, some of which related to local storage, so itās reasonable to read it all to understand how it works
lwt_direct
is designed to be a very light addition tolwt
that does as little as possible and relies onlwt
as much as possible, running in the same scheduler, etc. so it doesnāt add parallelism or a new kind of future.run
andawait
are similar to domainslibās eponymous functions:await
(the desirable part) allows direct style code to wait for promises, but it needs to run in a context with an event handler, hencerun
.
3 Likes