Skip to content

Commit 4e19719

Browse files
committed
modify signature for Moonpool_lwt.run_in_lwt_and_await
1 parent 4f68531 commit 4e19719

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/lwt/moonpool_lwt.ml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,6 @@ let fut_of_lwt (lwt_fut : _ Lwt.t) : _ M.Fut.t =
229229
fut
230230
)
231231

232-
let run_in_lwt_and_await (f : unit -> 'a Lwt.t) : 'a =
233-
if Main_state.on_lwt_thread () then (
234-
let fut = f () in
235-
await_lwt fut
236-
) else (
237-
let fut, prom = Fut.make () in
238-
Main_state.add_action_from_another_thread (fun () ->
239-
let lwt_fut = f () in
240-
transfer_lwt_to_fut lwt_fut prom);
241-
Fut.await fut
242-
)
243-
244232
module Setup_lwt_hooks (ARG : sig
245233
val st : Scheduler_state.st
246234
end) =
@@ -307,6 +295,7 @@ let spawn_lwt f : _ Lwt.t =
307295
lwt_fut
308296

309297
let spawn_lwt_ignore f = ignore (spawn_lwt f : unit Lwt.t)
298+
let run_in_lwt_and_await (f : unit -> 'a) : 'a = await_lwt @@ spawn_lwt f
310299
let on_lwt_thread = Main_state.on_lwt_thread
311300

312301
let lwt_main (f : _ -> 'a) : 'a =

src/lwt/moonpool_lwt.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ val await_lwt : 'a Lwt.t -> 'a
3535
runner. This must be run from within a Moonpool runner so that the await-ing
3636
effect is handled. *)
3737

38-
val run_in_lwt_and_await : (unit -> 'a Lwt.t) -> 'a
38+
val run_in_lwt_and_await : (unit -> 'a) -> 'a
39+
(** [run_in_lwt_and_await f] runs [f()] in the lwt thread, just like
40+
[spawn_lwt f], and then calls {!await_lwt} on the result. This means [f()]
41+
can use Lwt functions and libraries, use {!await_lwt} on them freely, etc,
42+
*)
3943

4044
(** {2 Wrappers around Lwt_main} *)
4145

0 commit comments

Comments
 (0)