mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
modify signature for Moonpool_lwt.run_in_lwt_and_await
This commit is contained in:
parent
4f685313de
commit
4e19719c4f
2 changed files with 6 additions and 13 deletions
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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} *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue