mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 11:15:38 -05:00
add No_runner: a runner that doesn't do anything in the background
The idea is that you might have APIs that want a runner, but the work is too trivial to require a full actual thread pool. In this case use `No_runner.runner` and calls to `run_async runner f` will turn into `f()`.
This commit is contained in:
parent
a3d3468b5e
commit
056f80b318
4 changed files with 26 additions and 3 deletions
|
|
@ -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_
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
9
src/no_runner.ml
Normal file
9
src/no_runner.ml
Normal file
|
|
@ -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 ())
|
||||
()
|
||||
6
src/no_runner.mli
Normal file
6
src/no_runner.mli
Normal file
|
|
@ -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. *)
|
||||
Loading…
Add table
Reference in a new issue