Documentation
¶
Overview ¶
Package rate provides a very simple rate limiter based on the passage of time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowSlice ¶
AllowSlice returns true if task may execute for the slice duration at time.Now()
Types ¶
type Limiter ¶
type Limiter interface {
// Quantum returns the duration allocated for every named task. This value is a
// limiter-scoped, maximum-duration watermark. It does not represent the quantum
// available for a specific task.
//
// If the Limiter is a aggregate of multiple Limiters, Quantum() should return the smallest
// time.Duration in the aggregate.
Quantum() time.Duration
// Schedule schedules the task to run for the given time slice if there is quantum
// available for that task.
//
// If the delay is <= 0 the task can run immediately and the time slice provided
// is subtracted from the task's quantum. If delay is > 0, the caller may wait the delay
// and attempt to schedule the task again, otherwise the task should be abandoned.
Schedule(task string, slice time.Duration) (delay time.Duration)
// Close closes the limiter
Close() error
}
Limiter provides a way to schedule named tasks for execution.
Click to show internal directories.
Click to hide internal directories.