package resp-client

  1. Overview
  2. Docs

Source file resp_client.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
include Resp_client_intf

module Make
    (Client : CLIENT)
    (S : Resp.S with type Reader.ic = Client.ic and type Writer.oc = Client.oc) =
struct
  include S
  open Lwt

  type t = Client.ic * Client.oc

  type params = Client.params

  let connect params = Client.connect params

  let read (ic, _) = S.read ic

  let write (_, oc) = S.write oc

  let decode (ic, _) = S.Reader.decode ic

  let read_lexeme (ic, _) =
    S.Reader.read_lexeme ic >>= fun x -> Resp.unwrap x |> Lwt.return

  let run_s client cmd =
    let cmd = List.to_seq cmd |> Seq.map (fun s -> Resp.string s) in
    write client (Array cmd) >>= fun () -> read client

  let run client cmd =
    let cmd = List.to_seq cmd in
    write client (Array cmd) >>= fun () -> read client
end