diff --git a/src/lwt/moonpool_lwt.ml b/src/lwt/moonpool_lwt.ml index 8338c009..91437fee 100644 --- a/src/lwt/moonpool_lwt.ml +++ b/src/lwt/moonpool_lwt.ml @@ -229,18 +229,6 @@ let fut_of_lwt (lwt_fut : _ Lwt.t) : _ M.Fut.t = fut ) -let run_in_lwt_and_await (f : unit -> 'a Lwt.t) : 'a = - if Main_state.on_lwt_thread () then ( - let fut = f () in - await_lwt fut - ) else ( - let fut, prom = Fut.make () in - Main_state.add_action_from_another_thread (fun () -> - let lwt_fut = f () in - transfer_lwt_to_fut lwt_fut prom); - Fut.await fut - ) - module Setup_lwt_hooks (ARG : sig val st : Scheduler_state.st end) = @@ -307,6 +295,7 @@ let spawn_lwt f : _ Lwt.t = lwt_fut let spawn_lwt_ignore f = ignore (spawn_lwt f : unit Lwt.t) +let run_in_lwt_and_await (f : unit -> 'a) : 'a = await_lwt @@ spawn_lwt f let on_lwt_thread = Main_state.on_lwt_thread let lwt_main (f : _ -> 'a) : 'a = diff --git a/src/lwt/moonpool_lwt.mli b/src/lwt/moonpool_lwt.mli index 2d8c9645..844ecdee 100644 --- a/src/lwt/moonpool_lwt.mli +++ b/src/lwt/moonpool_lwt.mli @@ -35,7 +35,11 @@ val await_lwt : 'a Lwt.t -> 'a runner. This must be run from within a Moonpool runner so that the await-ing effect is handled. *) -val run_in_lwt_and_await : (unit -> 'a Lwt.t) -> 'a +val run_in_lwt_and_await : (unit -> 'a) -> 'a +(** [run_in_lwt_and_await f] runs [f()] in the lwt thread, just like + [spawn_lwt f], and then calls {!await_lwt} on the result. This means [f()] + can use Lwt functions and libraries, use {!await_lwt} on them freely, etc, +*) (** {2 Wrappers around Lwt_main} *)