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
// We'll have a slot for each millisecond. | |
const slotCnt = int(time.Second / time.Millisecond) | |
type RateLimiter struct { | |
// rpsBufferMs is a ring buffer that contains a slot per millisecond. | |
rpsBufferMs [slotCnt]int | |
lastRpsValue int | |
lastSlot int | |
lastTime time.Time |