From ff257df69df359177a699563f51031c671af5ee8 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sun, 29 Oct 2023 17:11:48 -0400 Subject: [PATCH] add `Moonpool.run_async` --- src/moonpool.ml | 1 + src/moonpool.mli | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/moonpool.ml b/src/moonpool.ml index 21b4ccec..b7d225d2 100644 --- a/src/moonpool.ml +++ b/src/moonpool.ml @@ -2,6 +2,7 @@ let start_thread_on_some_domain f x = let did = Random.int (D_pool_.n_domains ()) in D_pool_.run_on_and_wait did (fun () -> Thread.create f x) +let run_async = Runner.run_async let recommended_thread_count () = Domain_.recommended_number () let spawn = Fut.spawn diff --git a/src/moonpool.mli b/src/moonpool.mli index 0e46bd02..3c470bd4 100644 --- a/src/moonpool.mli +++ b/src/moonpool.mli @@ -23,6 +23,12 @@ val start_thread_on_some_domain : ('a -> unit) -> 'a -> Thread.t to run the thread. This ensures that we don't always pick the same domain to run all the various threads needed in an application (timers, event loops, etc.) *) +val run_async : Runner.t -> (unit -> unit) -> unit +(** [run_async runner task] schedules the task to run + on the given runner. This means [task()] will be executed + at some point in the future, possibly in another thread. + @since NEXT_RELEASE *) + val recommended_thread_count : unit -> int (** Number of threads recommended to saturate the CPU. For IO pools this makes little sense (you might want more threads than