mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-18 00:26:43 -05:00
Compare commits
No commits in common. "2f0aa7a32616195c10d1a35e1167354993bff1e9" and "2af1237b7982247e236f21ec0c985e2216929246" have entirely different histories.
2f0aa7a326
...
2af1237b79
1 changed files with 8 additions and 17 deletions
|
|
@ -175,13 +175,6 @@ module Main_state = struct
|
||||||
Scheduler_state.add_action_from_another_thread_ (get_st ()) f
|
Scheduler_state.add_action_from_another_thread_ (get_st ()) f
|
||||||
end
|
end
|
||||||
|
|
||||||
let await_lwt_from_another_thread fut =
|
|
||||||
let tr = M.Trigger.create () in
|
|
||||||
Main_state.add_action_from_another_thread (fun () ->
|
|
||||||
register_trigger_on_lwt_termination fut tr);
|
|
||||||
M.Trigger.await_exn tr;
|
|
||||||
await_lwt_terminated fut
|
|
||||||
|
|
||||||
let await_lwt (fut : _ Lwt.t) =
|
let await_lwt (fut : _ Lwt.t) =
|
||||||
if Scheduler_state.on_lwt_thread_ (Main_state.get_st ()) then (
|
if Scheduler_state.on_lwt_thread_ (Main_state.get_st ()) then (
|
||||||
(* can directly access the future *)
|
(* can directly access the future *)
|
||||||
|
|
@ -193,8 +186,13 @@ let await_lwt (fut : _ Lwt.t) =
|
||||||
register_trigger_on_lwt_termination fut tr;
|
register_trigger_on_lwt_termination fut tr;
|
||||||
M.Trigger.await_exn tr;
|
M.Trigger.await_exn tr;
|
||||||
await_lwt_terminated fut
|
await_lwt_terminated fut
|
||||||
) else
|
) else (
|
||||||
await_lwt_from_another_thread fut
|
let tr = M.Trigger.create () in
|
||||||
|
Main_state.add_action_from_another_thread (fun () ->
|
||||||
|
register_trigger_on_lwt_termination fut tr);
|
||||||
|
M.Trigger.await_exn tr;
|
||||||
|
await_lwt_terminated fut
|
||||||
|
)
|
||||||
|
|
||||||
let lwt_of_fut (fut : 'a M.Fut.t) : 'a Lwt.t =
|
let lwt_of_fut (fut : 'a M.Fut.t) : 'a Lwt.t =
|
||||||
if not (Main_state.on_lwt_thread ()) then
|
if not (Main_state.on_lwt_thread ()) then
|
||||||
|
|
@ -297,16 +295,9 @@ let spawn_lwt f : _ Lwt.t =
|
||||||
lwt_fut
|
lwt_fut
|
||||||
|
|
||||||
let spawn_lwt_ignore f = ignore (spawn_lwt f : unit Lwt.t)
|
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 on_lwt_thread = Main_state.on_lwt_thread
|
||||||
|
|
||||||
let run_in_lwt_and_await (f : unit -> 'a) : 'a =
|
|
||||||
let st = Main_state.get_st () in
|
|
||||||
if Scheduler_state.on_lwt_thread_ st then
|
|
||||||
(* run immediately *)
|
|
||||||
f ()
|
|
||||||
else
|
|
||||||
await_lwt_from_another_thread @@ spawn_lwt f
|
|
||||||
|
|
||||||
let lwt_main (f : _ -> 'a) : 'a =
|
let lwt_main (f : _ -> 'a) : 'a =
|
||||||
let st = setup () in
|
let st = setup () in
|
||||||
(* make sure to cleanup *)
|
(* make sure to cleanup *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue