diff --git a/reddit_api_kernel/connection_state_machine.ml b/reddit_api_kernel/connection_state_machine.ml new file mode 100644 index 00000000..e69de29b diff --git a/reddit_api_kernel/connection_state_machine.mli b/reddit_api_kernel/connection_state_machine.mli new file mode 100644 index 00000000..645722ca --- /dev/null +++ b/reddit_api_kernel/connection_state_machine.mli @@ -0,0 +1,46 @@ +open! Core + +module When_to_send : sig + type t = + | Now + | Check_after_receiving_response + | After of Time_ns.t +end + +type t [@@deriving sexp_of] + +(** {1 Constructors} *) +val create : rate_limiter:Rate_limiter_state_machine.t -> t + +val by_headers : t +val with_minimum_delay : delay:Time_ns.Span.t -> t +val combine : t list -> t + +(** {1 Events} *) + +(* TODO: Move *) +module Access_token : sig + type t = + { token : string + ; expiration : Time_ns.t + } +end + +val send_request + : t + -> now:Time_ns.t + -> t * [ `Send_it | `Get_access_token | `Wait_until of Time_ns.t ] + +val got_access_token : t -> Access_token.t -> t + +(** -- *) + +(** [sent_request_unchecked] should called immediately after sending a request. + It is the caller's responsibility to first call {!wait_until}. *) +val sent_request_unchecked : t -> now:Time_ns.t -> t + +val received_response : t -> Cohttp.Response.t -> t + +(** {1 Accessors} *) + +val wait_until : t -> When_to_send.t