Skip to content

Commit

Permalink
WIP connection state machine
Browse files Browse the repository at this point in the history
  • Loading branch information
leviroth committed Dec 8, 2024
1 parent 9d0b0ba commit 833ae53
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Empty file.
46 changes: 46 additions & 0 deletions reddit_api_kernel/connection_state_machine.mli
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 833ae53

Please sign in to comment.