| 1 |
let () = |
| 2 |
let init = |
| 3 |
Dune_rpc.V1.Request.Initialize.create |
| 4 |
~id:(Dune_rpc.V1.Request.Id.make (Csexp.Atom "example_rpc_client")) |
| 5 |
in |
| 6 |
let where = Dune_rpc_lwt.V1.Where.default ~build_dir:"_build" () in |
| 7 |
Lwt_main.run |
| 8 |
(let open Lwt.Syntax in |
| 9 |
let open Lwt.Infix in |
| 10 |
let* chan = Dune_rpc_lwt.V1.connect_chan where in |
| 11 |
Dune_rpc_lwt.V1.Client.connect chan init ~f:(fun client -> |
| 12 |
print_endline "Sending ping to server..."; |
| 13 |
let* () = |
| 14 |
let* request = |
| 15 |
Dune_rpc_lwt.V1.Client.Versioned.prepare_request |
| 16 |
client |
| 17 |
Dune_rpc.V1.Request.ping |
| 18 |
>|= Result.get_ok |
| 19 |
in |
| 20 |
Dune_rpc_lwt.V1.Client.request client request () >|= Result.get_ok |
| 21 |
in |
| 22 |
print_endline "Got response from server..."; |
| 23 |
print_endline "Creating progress stream..."; |
| 24 |
let* progress_stream = |
| 25 |
Dune_rpc_lwt.V1.Client.poll client Dune_rpc.V1.Sub.progress >|= Result.get_ok |
| 26 |
in |
| 27 |
print_endline "Waiting for next progress event..."; |
| 28 |
let* progress_event = Dune_rpc_lwt.V1.Client.Stream.next progress_stream in |
| 29 |
let message = |
| 30 |
match progress_event with |
| 31 |
| None -> "(none)" |
| 32 |
| Some Success -> "Success" |
| 33 |
| Some Failed -> "Failed" |
| 34 |
| Some Interrupted -> "Interrupted" |
| 35 |
| Some (In_progress { complete; remaining; failed }) -> |
| 36 |
Printf.sprintf |
| 37 |
"In_progress { complete = %d; remaining = %d; failed = %d }" |
| 38 |
complete |
| 39 |
remaining |
| 40 |
failed |
| 41 |
| Some Waiting -> "Waiting" |
| 42 |
in |
| 43 |
print_endline (Printf.sprintf "Got progress_event: %s" message); |
| 44 |
print_endline "Shutting down RPC server..."; |
| 45 |
let* () = |
| 46 |
let* shutdown_notification = |
| 47 |
Dune_rpc_lwt.V1.Client.Versioned.prepare_notification |
| 48 |
client |
| 49 |
Dune_rpc.V1.Notification.shutdown |
| 50 |
>|= Result.get_ok |
| 51 |
in |
| 52 |
Dune_rpc_lwt.V1.Client.notification client shutdown_notification () |
| 53 |
in |
| 54 |
Lwt.return ())) |
| 55 |
;; |