diff --git a/src/moonpool.ml b/src/moonpool.ml index b46bc123..498a9fb3 100644 --- a/src/moonpool.ml +++ b/src/moonpool.ml @@ -3,19 +3,21 @@ let start_thread_on_some_domain f x = D_pool_.run_on_and_wait did (fun () -> Thread.create f x) let recommended_thread_count () = Domain_.recommended_number () +let spawn = Fut.spawn module Atomic = Atomic_ module Blocking_queue = Bb_queue module Bounded_queue = Bounded_queue module Chan = Chan +module Fifo_pool = Fifo_pool module Fork_join = Fork_join module Fut = Fut module Lock = Lock +module No_runner = No_runner module Pool = Fifo_pool -module Ws_pool = Ws_pool module Runner = Runner -module Fifo_pool = Fifo_pool module Thread_local_storage = Thread_local_storage +module Ws_pool = Ws_pool module Private = struct module Ws_deque_ = Ws_deque_ diff --git a/src/moonpool.mli b/src/moonpool.mli index 4360c6ee..05b8649c 100644 --- a/src/moonpool.mli +++ b/src/moonpool.mli @@ -12,9 +12,10 @@ module Ws_pool = Ws_pool module Fifo_pool = Fifo_pool module Runner = Runner +module No_runner = No_runner module Pool = Fifo_pool -[@@deprecated "use Fifo_pool or Ws_pool"] +[@@deprecated "use Fifo_pool or Ws_pool to be more explicit"] (** Default pool. Please explicitly pick an implementation instead. *) val start_thread_on_some_domain : ('a -> unit) -> 'a -> Thread.t @@ -28,6 +29,11 @@ val recommended_thread_count : unit -> int this because many of them will be blocked most of the time). @since NEXT_RELEASE *) +val spawn : on:Runner.t -> (unit -> 'a) -> 'a Fut.t +(** [spawn ~on f] runs [f()] on the runner (a thread pool typically) + and returns a future result for it. See {!Fut.spawn}. + @since NEXT_RELEASE *) + module Lock = Lock module Fut = Fut module Chan = Chan diff --git a/src/no_runner.ml b/src/no_runner.ml new file mode 100644 index 00000000..d5e11284 --- /dev/null +++ b/src/no_runner.ml @@ -0,0 +1,9 @@ +include Runner + +let runner : t = + Runner.For_runner_implementors.create + ~size:(fun () -> 0) + ~num_tasks:(fun () -> 0) + ~shutdown:(fun ~wait:_ () -> ()) + ~run_async:(fun f -> f ()) + () diff --git a/src/no_runner.mli b/src/no_runner.mli new file mode 100644 index 00000000..2c295adc --- /dev/null +++ b/src/no_runner.mli @@ -0,0 +1,6 @@ +(** Runner that runs in the caller, not in the background. *) + +include module type of Runner + +val runner : t +(** The trivial runner that actually runs tasks at the calling point. *)