Source

screentime-monitor / client_common.mli

open Core.Std
open Async.Std

module Config : sig
  type t = { server: string
           ; user: Username.t sexp_option
           } 
  with sexp
end

val spinner : (unit -> string) Lazy.t
val load_config : unit -> Config.t Deferred.t
val get_username : unit -> Username.t Deferred.t

val username_spec : Username.t Command.Spec.Arg_type.t
val category_spec : Category.t Command.Spec.Arg_type.t

(** Returns a deferred which becomes determined when the term signal
    is hit *)
val on_term_signal : unit Deferred.t lazy_t
val shared_flags : unit -> (Username.t option -> 'a, 'a) Command.Spec.t
val days_flag : unit -> int Command.Spec.param
val edit_file
  : (module Core.Std.Sexpable with type t = 'a)
  -> editor:string
  -> tempfile:string
  -> 'a With_format.t option Deferred.t

val shell_run : string -> string list -> string Deferred.t
val clear_string : string Deferred.t lazy_t
val clear_screen : unit -> unit Deferred.t

val with_rpc_conn
  :  (Rpc.Connection.t -> 'a Deferred.t)
  -> host:string -> port:int
  -> 'a Deferred.t

val setup_conn
  :  Username.t option
  -> (Username.t -> Rpc.Connection.t -> 'a Deferred.t)
  -> 'a Deferred.t

module Robust_connection : sig
  type t
  val get : t -> Rpc.Connection.t option

  val with_connect
    :  reconnect_after:Time.Span.t
    -> 'addr Tcp.where_to_connect
    -> (t -> 'a Deferred.t)
    -> 'a Deferred.t

end

val setup_robust_conn
  :  reconnect_after:Core.Span.t
  -> Username.t option
  -> (Username.t -> Robust_connection.t -> 'a Deferred.t)
  -> 'a Deferred.t


(** Retries the function in question until it gets an [Ok] response.
    If the provided function throws an exception, the retry loop will
    end *)
val retry
  :  ?retry_after:Time.Span.t
  -> ?num_tries:[`Unbounded | `At_most of int ]
  -> ?on_error:('b -> unit)
  -> ?on_retry:(unit -> unit)
  -> (unit -> ('a,'b) Result.t Deferred.t)
  -> ('a,'b) Result.t Deferred.t