Skip to content

Commit

Permalink
Merge pull request #371 from talex5/get_loop
Browse files Browse the repository at this point in the history
Expose Eio_luv.Low_level.get_loop
  • Loading branch information
talex5 authored Nov 21, 2022
2 parents 35feb3a + 9d1cafe commit d24af9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib_eio_luv/eio_luv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ let enqueue_at_head t k v =
Lf_queue.push_head t.run_q (Thread (fun () -> Suspended.continue k v));
Luv.Async.send t.async |> or_raise

let get_loop () =
enter_unchecked @@ fun t k ->
Suspended.continue k t.loop

let unix_fstat fd =
let ust = Unix.LargeFile.fstat fd in
let st_kind : Eio.File.Stat.kind =
Expand Down Expand Up @@ -282,6 +278,10 @@ module Low_level = struct
exception Luv_error = Luv_error
let or_raise = or_raise

let get_loop () =
enter_unchecked @@ fun t k ->
Suspended.continue k t.loop

let await fn =
Effect.perform (Await fn)

Expand Down
16 changes: 15 additions & 1 deletion lib_eio_luv/eio_luv.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ module Low_level : sig

exception Luv_error of Luv.Error.t

val get_loop : unit -> Luv.Loop.t
(** [get_loop ()] returns the current fiber's event loop.
When using the {!Luv} API directly, you {b must} pass this to any Luv function
that accepts a loop as an optional argument in order to use the resource with Eio.
The wrapper functions in this file all do this for you. *)

val or_raise : 'a or_error -> 'a
(** [or_raise (Error e)] raises [Luv_error e]. *)

Expand Down Expand Up @@ -108,12 +115,19 @@ module Low_level : sig

val to_luv : 'a t -> 'a Luv.Handle.t
(** [to_luv t] returns the wrapped handle.
This allows unsafe access to the handle.
@raise Invalid_arg if [t] is closed. *)

val of_luv : ?close_unix:bool -> sw:Switch.t -> 'a Luv.Handle.t -> 'a t
(** [of_luv ~sw h] wraps [h] as an open handle.
This is unsafe if [h] is closed directly (before or after wrapping it).
You {b must} pass the loop (from {!get_loop}) to any Luv function
that accepts one as an optional argument
in order to use the resource with the correct event loop.
This function is unsafe if [h] is closed directly (before or after wrapping it).
@param sw The handle is closed when [sw] is released, if not closed manually first.
@param close_unix if [true] (the default), calling [close] also closes [fd]. *)
end
Expand Down

0 comments on commit d24af9a

Please sign in to comment.