package ez_api

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file ezWsCommon.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
33
34
35
36
37
38
39
40
41
42
43
44
45
(**************************************************************************)
(*                                                                        *)
(*                 Copyright 2018-2023 OCamlPro                           *)
(*                                                                        *)
(*  All rights reserved. This file is distributed under the terms of the  *)
(*  GNU Lesser General Public License version 2.1, with the special       *)
(*  exception on linking described in the file LICENSE.                   *)
(*                                                                        *)
(**************************************************************************)

module type S = sig
  type 'a rp = ('a, string) result Lwt.t

  type 'a action = {
    send : 'a -> unit rp;
    close : int option -> unit rp
  }

  type 'a ws = {
    action : 'a action;
    conn : unit rp
  }
end

module Types = struct
  type 'a rp = ('a, string) result Lwt.t

  type 'a action = {
    send : 'a -> unit rp;
    close : int option -> unit rp
  }

  type 'a ws = {
    action : 'a action;
    conn : unit rp
  }
end

let log ?(action="recv") url =
  Option.iter @@ fun msg -> EzDebug.printf "[>%s %s %s]" msg action url

let res_encoding err ok = Json_encoding.(union [
    case ok Result.to_option Result.ok;
    case err (function Error e -> Some e | _ -> None) Result.error
  ])