Skip to content

Commit d24af9a

Browse files
authored
Merge pull request #371 from talex5/get_loop
Expose Eio_luv.Low_level.get_loop
2 parents 35feb3a + 9d1cafe commit d24af9a

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lib_eio_luv/eio_luv.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,6 @@ let enqueue_at_head t k v =
245245
Lf_queue.push_head t.run_q (Thread (fun () -> Suspended.continue k v));
246246
Luv.Async.send t.async |> or_raise
247247

248-
let get_loop () =
249-
enter_unchecked @@ fun t k ->
250-
Suspended.continue k t.loop
251-
252248
let unix_fstat fd =
253249
let ust = Unix.LargeFile.fstat fd in
254250
let st_kind : Eio.File.Stat.kind =
@@ -282,6 +278,10 @@ module Low_level = struct
282278
exception Luv_error = Luv_error
283279
let or_raise = or_raise
284280

281+
let get_loop () =
282+
enter_unchecked @@ fun t k ->
283+
Suspended.continue k t.loop
284+
285285
let await fn =
286286
Effect.perform (Await fn)
287287

lib_eio_luv/eio_luv.mli

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ module Low_level : sig
1212

1313
exception Luv_error of Luv.Error.t
1414

15+
val get_loop : unit -> Luv.Loop.t
16+
(** [get_loop ()] returns the current fiber's event loop.
17+
18+
When using the {!Luv} API directly, you {b must} pass this to any Luv function
19+
that accepts a loop as an optional argument in order to use the resource with Eio.
20+
The wrapper functions in this file all do this for you. *)
21+
1522
val or_raise : 'a or_error -> 'a
1623
(** [or_raise (Error e)] raises [Luv_error e]. *)
1724

@@ -108,12 +115,19 @@ module Low_level : sig
108115

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

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

0 commit comments

Comments
 (0)