feat: add Runner.dummy

This commit is contained in:
Simon Cruanes 2024-03-04 15:18:18 -05:00
parent 66f95df3b4
commit 51459f9b0b
3 changed files with 14 additions and 1 deletions

View file

@ -43,5 +43,14 @@ module For_runner_implementors = struct
let k_cur_runner : t option ref TLS.key = Types_.k_cur_runner
end
let dummy : t =
For_runner_implementors.create
~size:(fun () -> 0)
~num_tasks:(fun () -> 0)
~shutdown:(fun ~wait:_ () -> ())
~run_async:(fun ~ls:_ _ ->
failwith "Runner.dummy: cannot actually run tasks")
()
let get_current_runner = get_current_runner
let get_current_storage = get_current_storage

View file

@ -51,6 +51,10 @@ val run_wait_block : ?ls:Task_local_storage.t -> t -> (unit -> 'a) -> 'a
about the required discipline to avoid deadlocks).
@raise Shutdown if the runner was already shut down *)
val dummy : t
(** Runner that fails when scheduling tasks on it.
Calling {!run_async} on it will raise Failure. *)
(** {2 Implementing runners} *)
(** This module is specifically intended for users who implement their

View file

@ -65,7 +65,7 @@ let create_done_ ~res () : _ t =
@@ Alive { children = FM.empty; on_cancel = Int_map.empty; cancel_id = 0 };
id;
res;
runner = Immediate_runner.runner;
runner = Runner.dummy;
ls = Task_local_storage.dummy;
}