@@ -21,17 +21,19 @@ let make_request ~scheme ~service ~rpc =
21
21
22
22
let call ~service ~rpc ?(scheme = " https" ) ~handler ~do_request () =
23
23
let request = make_request ~service ~rpc ~scheme in
24
- let write_body, write_body_notify = Lwt. wait () in
25
- let out, notify_out = Lwt. wait () in
24
+ let read_body, read_body_notify = Lwt. wait () in
25
+ let handler_res, handler_res_notify = Lwt. wait () in
26
+ let out, out_notify = Lwt. wait () in
26
27
let response_handler (response : H2.Response.t ) body =
28
+ Lwt. wakeup_later read_body_notify body;
27
29
Lwt. async (fun () ->
28
30
if response.status <> `OK then (
29
- Lwt. wakeup_later notify_out
31
+ Lwt. wakeup_later out_notify
30
32
(Error (Grpc.Status. v Grpc.Status. Unknown ));
31
33
Lwt. return_unit )
32
34
else
33
- let + out = handler write_body body in
34
- Lwt. wakeup_later notify_out (Ok out ))
35
+ let + handler_res = handler_res in
36
+ Lwt. wakeup_later out_notify (Ok handler_res ))
35
37
in
36
38
let status, status_notify = Lwt. wait () in
37
39
let trailers_handler headers =
@@ -50,23 +52,26 @@ let call ~service ~rpc ?(scheme = "https") ~handler ~do_request () =
50
52
let status = Grpc.Status. v ?message code in
51
53
Lwt. wakeup_later status_notify status
52
54
in
53
- let body =
55
+ let write_body =
54
56
do_request ?trailers_handler:(Some trailers_handler) request
55
57
~response_handler
56
58
in
57
- Lwt. wakeup_later write_body_notify body;
59
+ Lwt. async (fun () ->
60
+ let + handler_res = handler write_body read_body in
61
+ Lwt. wakeup_later handler_res_notify handler_res);
58
62
let * out = out in
59
63
let + status = status in
60
64
match out with Error _ as e -> e | Ok out -> Ok (out, status)
61
65
62
66
module Rpc = struct
63
67
type 'a handler =
64
- [ `write ] H2.Body .t Lwt .t -> [ `read ] H2.Body .t -> 'a Lwt .t
68
+ [ `write ] H2.Body .t -> [ `read ] H2.Body .t Lwt .t -> 'a Lwt .t
65
69
66
70
let bidirectional_streaming ~f write_body read_body =
67
- let * write_body = write_body in
68
71
let decoder_stream, decoder_push = Lwt_stream. create () in
69
- Connection. grpc_recv_streaming read_body decoder_push;
72
+ Lwt. async (fun () ->
73
+ let + read_body = read_body in
74
+ Connection. grpc_recv_streaming read_body decoder_push);
70
75
let encoder_stream, encoder_push = Lwt_stream. create () in
71
76
Lwt. async (fun () ->
72
77
Connection. grpc_send_streaming_client write_body encoder_stream);
0 commit comments