@@ -14,10 +14,11 @@ let or_fail = function
14
14
| Ok x -> x
15
15
| Error (`Msg m ) -> failwith m
16
16
17
- let start_server () =
17
+ let start_server ~ switch () =
18
18
let config = Capnp_rpc_unix.Vat_config. create ~secret_key listen_address in
19
19
let make_sturdy = Capnp_rpc_unix.Vat_config. sturdy_uri config in
20
20
let services = Restorer.Table. create make_sturdy in
21
+ Lwt_switch. add_hook (Some switch) (fun () -> Restorer.Table. clear services; Lwt. return_unit);
21
22
let restore = Restorer. of_table services in
22
23
(* $MDX part-begin=root *)
23
24
let root_id = Capnp_rpc_unix.Vat_config. derived_id config " root" in
@@ -27,18 +28,20 @@ let start_server () =
27
28
in
28
29
(* $MDX part-end *)
29
30
Restorer.Table. add services root_id root;
30
- Capnp_rpc_unix. serve config ~restore > |= fun _vat ->
31
+ Capnp_rpc_unix. serve ~switch config ~restore > |= fun _vat ->
31
32
Capnp_rpc_unix.Vat_config. sturdy_uri config root_id
32
33
33
34
let run_client cap_file =
34
- let vat = Capnp_rpc_unix. client_only_vat () in
35
+ Lwt_switch. with_switch @@ fun switch ->
36
+ let vat = Capnp_rpc_unix. client_only_vat ~switch () in
35
37
let sr = Capnp_rpc_unix.Cap_file. load vat cap_file |> or_fail in
36
38
Sturdy_ref. with_cap_exn sr @@ fun for_alice ->
37
39
Logger. log for_alice " Message from Alice"
38
40
39
41
let () =
40
42
Lwt_main. run begin
41
- start_server () >> = fun root_uri ->
43
+ Lwt_switch. with_switch @@ fun switch ->
44
+ start_server ~switch () >> = fun root_uri ->
42
45
let vat = Capnp_rpc_unix. client_only_vat () in
43
46
let root_sr = Capnp_rpc_unix.Vat. import vat root_uri |> or_fail in
44
47
Sturdy_ref. with_cap_exn root_sr @@ fun root ->
0 commit comments