Skip to content

Commit 32092aa

Browse files
committed
rate-limit: Clarify token bucket creation docs
Creating a token bucket fails if the rate limit supplied is 0 or negative - this can lead to unexpected and undesirable behaviour, such as division by 0 or negative token counts. Signed-off-by: Christian Pardillo Laursen <[email protected]>
1 parent fbf70b1 commit 32092aa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ocaml/libs/rate-limit/token_bucket.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type t
3636

3737
val create : burst_size:float -> fill_rate:float -> t option
3838
(** Create token bucket with given parameters.
39+
Returns None if the fill rate is 0 or negative.
3940
@param burst_size Maximum number of tokens that can fit in the bucket
4041
@param fill_rate Number of tokens added to the bucket per second
4142
*)
@@ -70,14 +71,15 @@ val delay_then_consume : t -> float -> unit
7071
val create_with_timestamp :
7172
Mtime.span -> burst_size:float -> fill_rate:float -> t option
7273
(** Create token bucket with given parameters and supplied inital timestamp
74+
Returns None if the fill_rate is 0 or negative.
7375
@param timestamp Initial timestamp
7476
@param burst_size Maximum number of tokens that can fit in the bucket
7577
@param fill_rate Number of tokens added to the bucket per second
7678
*)
7779

7880
val peek_with_timestamp : Mtime.span -> t -> float
7981
(** Retrieve token amount in token bucket at given timestamp.
80-
Undefined behaviour when [timestamp] <= [tb.timestamp]
82+
Undefined behaviour when [timestamp] <= [tb.timestamp]
8183
@param timestamp Current time
8284
@param tb Token bucket
8385
@return Amount of tokens in the token bucket

0 commit comments

Comments
 (0)