package fuseau-lwt

  1. Overview
  2. Docs

Interoperability between Fuseau and Lwt.

This combines Fuseau's fibers with the Lwt event loop (ie Lwt_engine) to deal with timers and file descriptors readiness. In essence, one can use fibers and structured concurrency from Fuseau alongside Lwt libraries and Lwt IO operations.

Re-export of fuseau

include module type of struct include Fuseau end
module Fiber_handle = Fuseau.Fiber_handle
module Event = Fuseau.Event
type !'ret branch = 'ret Event.branch =
  1. | When : 'a Event.t * ('a -> 'ret0) -> 'ret0 branch
val select : 'ret branch list -> 'ret
module Chan = Fuseau.Chan
module Exn_bt = Fuseau.Exn_bt
module Time = Fuseau.Time
module Fiber = Fuseau.Fiber
module FLS = Fuseau.FLS
exception Inactive
module Scheduler = Fuseau.Scheduler
module Event_loop : sig ... end
module Resource_pool = Fuseau.Resource_pool
module Buf_pool = Fuseau.Buf_pool
module Cancel_handle : sig ... end
val sleep_s : float -> unit
exception Timeout
val await : 'a Fiber.t -> 'a
val try_await : 'a Fiber.t -> 'a Exn_bt.result
val cancel_after_s : float -> unit
val ev_timeout : float -> 'a Event.t
val ev_deadline : float -> 'a Event.t
val with_cancel_callback : (Exn_bt.t -> unit) -> (unit -> 'a) -> 'a
val spawn : ?name:string -> ?propagate_cancel_to_parent:bool -> (unit -> 'a) -> 'a Fiber.t
val spawn_from_anywhere : ?name:string -> Scheduler.t -> (unit -> 'a) -> 'a Fiber.t
val spawn_as_child_of : ?name:string -> ?propagate_cancel_to_parent:bool -> Scheduler.t -> 'b Fiber.t -> (unit -> 'a) -> 'a Fiber.t
val schedule_micro_task : (unit -> unit) -> unit
val yield : unit -> unit
val get_scheduler : unit -> Scheduler.t
module Private_ = Fuseau.Private_

Interop with Lwt

Here we have functions that are used to cross the boundary between the Fuseau world and the Lwt world.

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

Like Fuseau.await but on a Lwt promise.

val spawn_as_lwt : ?parent:_ Fiber.t -> ?name:string -> ?propagate_cancel_to_parent:bool -> (unit -> 'a) -> 'a Lwt.t

spawn_as_lwt f runs f() in the Fuseau+Lwt thread, and returns a Lwt future that resolves when the fiber does

val spawn_as_lwt_from_anywhere : ?name:string -> Scheduler.t -> (unit -> 'a) -> 'a Lwt.t

spawn_from_anywhere scheduler f runs f() as a toplevel fiber in scheduler. It can be run from another thread.

module IO_lwt : sig ... end

IO through Lwt's engine

val ev_read : Unix.file_descr -> bytes -> int -> int -> int Event.t

ev_read fd buf i len is an event that, when ready, will ready at most len bytes from fd into buf[i.. i+len], and return how many bytes were read. It uses Lwt_engine to wait for fd's readiness.

val ev_write : Unix.file_descr -> bytes -> int -> int -> int Event.t

ev_write fd buf i len is an event that, when ready, writes at most len bytes from buf into fd. It uses Lwt_engine to wait for fd's readiness.

module Iostream : sig ... end

Iostream specialized for Lwt

module Net : sig ... end

Networking using Lwt_io

Main loop

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

Run main loop, using the current Lwt_engine.t.

OCaml

Innovation. Community. Security.