Library
Module
Module type
Parameter
Class
Class type
module Token : sig ... end
val with_event_loop : clock:Eio.Time.clock -> (Token.t -> 'a) -> 'a
with_event_loop ~clock fn
starts an Lwt event loop running and then executes fn t
. When that finishes, the event loop is stopped.
module Promise : sig ... end
val run_eio : (unit -> 'a) -> 'a Lwt.t
run_eio fn
allows running Eio code from within a Lwt function. It runs fn ()
in a new Eio fiber and returns a promise for the result. If the returned promise is cancelled, it will cancel the Eio fiber. The new fiber is attached to the Lwt event loop's switch and will also be cancelled if the function passed to with_event_loop
returns.
val run_lwt : (unit -> 'a Lwt.t) -> 'a
run_lwt fn
allows running Lwt code from within an Eio function. It runs fn ()
to create a Lwt promise and then awaits it. If the Eio fiber is cancelled, the Lwt promise is cancelled too.
notify ()
causes Lwt_engine.iter
to return, indicating that the event loop should run the hooks and resume yielded threads. Ideally, you should call this when an Eio fiber wakes up a Lwt thread, e.g. by resolving a Lwt promise. In most cases however this isn't really needed, since Lwt_unix.yield
is deprecated and Lwt.pause
will call this automatically.