Documentation
¶
Overview ¶
package doevery provides primitives for per-call-site rate-limiting.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TimePeriod ¶
TimePeriod rate limits each call site of this by the duration specified as the first argument. This may be useful in logging scenarios, where you only want to log every few seconds - or every second - instead of tens of hundreds of times per second.
Each unique call site that calls TimePeriod is rate-limited independently. Each invocation of TimePeriod at the same call-site should provide the same duration.
Example usage:
end := time.Now().Add(5 * time.Second) for end.After(time.Now()) { doevery.TimePeriod(1*time.Second, func() { fmt.Println("This will only appear once per second.") }) }
Please note that each individual thread does not have a distinct rate-limit; the rate-limit is global for the file/line.
TimePeriod is safe for concurrent use.
Types ¶
This section is empty.