@@ -25,17 +25,40 @@ let raise_rpc_error (e : Rpc_error.t) =
2525 ]
2626;;
2727
28+ type ('a, 'b) message_kind =
29+ | Request : ('a , 'b ) Dune_rpc.Decl .request -> ('a , 'b ) message_kind
30+ | Notification : 'a Dune_rpc.Decl .notification -> ('a , unit ) message_kind
31+
2832let request_exn client request arg =
2933 let * decl =
3034 Client.Versioned. prepare_request client (Dune_rpc.Decl.Request. witness request)
3135 in
3236 match decl with
33- | Ok decl ->
34- let + res = Client. request client decl arg in
37+ | Ok decl -> Client. request client decl arg
38+ | Error e -> raise (Dune_rpc.Version_error. E e)
39+ ;;
40+
41+ let notify_exn client notification arg =
42+ let * res =
43+ Client.Versioned. prepare_notification
44+ client
45+ (Dune_rpc.Decl.Notification. witness notification)
46+ in
47+ match res with
48+ | Ok decl -> Client. notification client decl arg
49+ | Error e -> raise (Dune_rpc.Version_error. E e)
50+ ;;
51+
52+ let prepare_message_and_send : type b . Client. t -> ('a , b ) message_kind -> 'a -> b Fiber. t
53+ =
54+ fun client message arg ->
55+ match message with
56+ | Notification witness -> notify_exn client witness arg
57+ | Request witness ->
58+ let + res = request_exn client witness arg in
3559 (match res with
36- | Ok response -> response
60+ | Ok ( result : b ) -> result
3761 | Error e -> raise_rpc_error e)
38- | Error e -> raise (Dune_rpc.Version_error. E e)
3962;;
4063
4164let client_term builder f =
@@ -86,13 +109,13 @@ let warn_ignore_arguments lock_held_by =
86109 ]
87110;;
88111
89- let fire_request
112+ let fire_message
90113 ~name
91114 ~wait
92115 ?(warn_forwarding = true )
93116 ?(lock_held_by = Dune_util.Global_lock.Lock_held_by. Unknown )
94117 builder
95- request
118+ message
96119 arg
97120 =
98121 let * connection = establish_client_session ~wait in
@@ -101,7 +124,7 @@ let fire_request
101124 Dune_rpc_impl.Client. client
102125 connection
103126 (Dune_rpc.Initialize.Request. create ~id: (Dune_rpc.Id. make (Sexp. Atom name)))
104- ~f: (fun client -> request_exn client request arg)
127+ ~f: (fun client -> prepare_message_and_send client message arg)
105128;;
106129
107130let wrap_build_outcome_exn ~print_on_success build_outcome =
0 commit comments