package moonpool-lwt

  1. Overview
  2. Docs

Module Moonpool_lwtSource

Lwt_engine-based event loop for Moonpool.

In what follows, we mean by "lwt thread" the thread running Lwt_main.run (so, the thread where the Lwt event loop and all Lwt callbacks execute).

NOTE: this is experimental and might change in future versions.

  • since 0.6

Basic conversions

Sourceval fut_of_lwt : 'a Lwt.t -> 'a Moonpool.Fut.t

fut_of_lwt lwt_fut makes a thread-safe moonpool future that completes when lwt_fut does. This must be run from within the Lwt thread.

Sourceval lwt_of_fut : 'a Moonpool.Fut.t -> 'a Lwt.t

lwt_of_fut fut makes a lwt future that completes when fut does. This must be called from the Lwt thread, and the result must always be used only from inside the Lwt thread.

Helpers on the moonpool side

Sourceval await_lwt : 'a Lwt.t -> 'a

await_lwt fut awaits a Lwt future from inside a task running on a moonpool runner. This must be run from within a Moonpool runner so that the await-ing effect is handled.

Sourceval run_in_lwt : (unit -> 'a Lwt.t) -> 'a Moonpool.Fut.t

run_in_lwt f runs f() from within the Lwt thread and returns a thread-safe future. This can be run from anywhere.

Sourceval run_in_lwt_and_await : (unit -> 'a Lwt.t) -> 'a

run_in_lwt_and_await f runs f in the Lwt thread, and awaits its result. Must be run from inside a moonpool runner so that the await-in effect is handled.

This is similar to Moonpool.await @@ run_in_lwt f.

Sourceval get_runner : unit -> Moonpool.Runner.t

Returns the runner from within which this is called. Must be run from within a fiber.

  • raises Failure

    if not run within a fiber

IO

Sourcemodule IO : sig ... end

IO using the Lwt event loop.

Sourcemodule IO_in : sig ... end

Input channel

Sourcemodule IO_out : sig ... end

Output channel

Sourcemodule TCP_server : sig ... end
Sourcemodule TCP_client : sig ... end

Helpers on the lwt side

Sourceval detach_in_runner : runner:Moonpool.Runner.t -> (unit -> 'a) -> 'a Lwt.t

detach_in_runner ~runner f runs f in the given moonpool runner, and returns a lwt future. This must be run from within the thread running Lwt_main.

Wrappers around Lwt_main

Sourceval main_with_runner : runner:Moonpool.Runner.t -> (unit -> 'a) -> 'a

main_with_runner ~runner f starts a Lwt-based event loop and runs f() inside a fiber in runner.

Sourceval main : (unit -> 'a) -> 'a

Like main_with_runner but with a default choice of runner.

OCaml

Innovation. Community. Security.