From 8bd79c70b57276d3ad834b73ba6bb43290e72754 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 8 Sep 2025 15:46:26 -0400 Subject: [PATCH] add Moonpool_lwt.on_lwt_thread --- src/lwt/moonpool_lwt.ml | 1 + src/lwt/moonpool_lwt.mli | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/lwt/moonpool_lwt.ml b/src/lwt/moonpool_lwt.ml index 4838a3fb..8338c009 100644 --- a/src/lwt/moonpool_lwt.ml +++ b/src/lwt/moonpool_lwt.ml @@ -307,6 +307,7 @@ let spawn_lwt f : _ Lwt.t = lwt_fut let spawn_lwt_ignore f = ignore (spawn_lwt f : unit Lwt.t) +let on_lwt_thread = Main_state.on_lwt_thread let lwt_main (f : _ -> 'a) : 'a = let st = setup () in diff --git a/src/lwt/moonpool_lwt.mli b/src/lwt/moonpool_lwt.mli index 63fb97c7..2d8c9645 100644 --- a/src/lwt/moonpool_lwt.mli +++ b/src/lwt/moonpool_lwt.mli @@ -45,6 +45,11 @@ val lwt_main : (Moonpool.Runner.t -> 'a) -> 'a (** [lwt_main f] sets the moonpool-lwt bridge up, runs lwt main, calls [f], destroys the bridge, and return the result of [f()]. *) +val on_lwt_thread : unit -> bool +(** [on_lwt_thread ()] is true if the current thread is the one currently + running {!lwt_main}. + @raise Failure if {!lwt_main} was not called. *) + val lwt_main_runner : unit -> Moonpool.Runner.t (** The runner from {!lwt_main}. The runner is only going to work if {!lwt_main} is currently running in some thread.