feat(blockingIO): allow to change the spawn function

This commit is contained in:
Simon Cruanes 2021-04-21 17:41:43 -04:00
parent e77fded638
commit 13feb606d2
2 changed files with 11 additions and 2 deletions

View file

@ -14,7 +14,7 @@ let fail = raise
let stdin = stdin let stdin = stdin
let stdout = stdout let stdout = stdout
let spawn f = let default_spawn_ f =
let run () = let run () =
try f() try f()
with e -> with e ->
@ -22,9 +22,14 @@ let spawn f =
"uncaught exception in `spawn`:\n%s\n%!" "uncaught exception in `spawn`:\n%s\n%!"
(Printexc.to_string e)); (Printexc.to_string e));
raise e raise e
in in
ignore (Thread.create run () : Thread.t) 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 = let catch f g =
try f() try f()
with e -> g e with e -> g e

View file

@ -4,3 +4,7 @@
include Sigs.IO with type 'a t = 'a include Sigs.IO with type 'a t = 'a
and type in_channel = in_channel and type in_channel = in_channel
and type out_channel = out_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. *)