typeRateLimiterinterface{// When gets an item and gets to decide how long that item should wait
//當一個物件放入的時候,需要回傳延遲多久(可自定義規則,等等會看到)
When(iteminterface{})time.Duration// Forget indicates that an item is finished being retried. Doesn't matter whether its for perm failing
// or for success, we'll stop tracking it
//當一個物件完成的時候可以,要忘記曾經延遲過(重新計算)
Forget(iteminterface{})// NumRequeues returns back how many failures the item has had
// 回傳物件已經放入幾次(重試了幾次,白話一點呼叫NumRequeues幾次)
NumRequeues(iteminterface{})int}
看完了抽象的定義之後,必須要回過來看 Max Of RateLimiter queue 實際物件定義了哪些屬性
// MaxOfRateLimiter calls every RateLimiter and returns the worst case response
// When used with a token bucket limiter, the burst could be apparently exceeded in cases where particular items
// were separately delayed a longer time.
typeMaxOfRateLimiterstruct{limiters[]RateLimiter//定義一個實作集合RateLimiter比如前幾個章節有提到的 ItemExponentialFailureRateLimiter、ItemFastSlowRateLimiter都可以放到這個集合內
}
funcNewRateLimitingQueue(rateLimiterRateLimiter)RateLimitingInterface{return&rateLimitingType{DelayingInterface:NewDelayingQueue(),//前一小節有提到過delating work queue的newfunction
rateLimiter:rateLimiter,//自行實作的rateLimiter
}}