-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |