diff --git a/src/blocking_IO.ml b/src/blocking_IO.ml index 845d46aa..81a04132 100644 --- a/src/blocking_IO.ml +++ b/src/blocking_IO.ml @@ -14,7 +14,7 @@ let fail = raise let stdin = stdin let stdout = stdout -let spawn f = +let default_spawn_ f = let run () = try f() with e -> @@ -22,9 +22,14 @@ let spawn f = "uncaught exception in `spawn`:\n%s\n%!" (Printexc.to_string e)); raise e -in + in ignore (Thread.create run () : Thread.t) +let spawn_ref_ = ref default_spawn_ + +let set_spawn_function f = spawn_ref_ := f +let spawn f = !spawn_ref_ f + let catch f g = try f() with e -> g e diff --git a/src/blocking_IO.mli b/src/blocking_IO.mli index 0ffde6ef..bdec4dbe 100644 --- a/src/blocking_IO.mli +++ b/src/blocking_IO.mli @@ -4,3 +4,7 @@ include Sigs.IO with type 'a t = 'a and type in_channel = in_channel and type out_channel = out_channel + +val set_spawn_function : ((unit -> unit) -> unit) -> unit +(** Change the way the LSP server spawns new threads to handle + client queries. For example, one might use a thread pool. *)