Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSystemStopped is returned when a user tries to schedule a timeout after stopping the // timeout system. ErrSystemStopped = errors.New("Timeout System is stopped") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*opts)
Option is a configuration option to NewTimeoutWheel
func WithBucketsExponent ¶
WithBucketsExponent sets the number of buckets in the hash table.
func WithLocksExponent ¶
WithLocksExponent sets the number locks in the lockpool used to lock the time buckets. If the number is greater than the number of buckets, the number of buckets will be used instead.
func WithTickInterval ¶
WithTickInterval sets the frequency of ticks.
type Timeout ¶
type Timeout struct {
// contains filtered or unexported fields
}
Timeout represents a single timeout function pending expiration.
type TimeoutWheel ¶
type TimeoutWheel struct {
// contains filtered or unexported fields
}
TimeoutWheel is a bucketed collection of Timeouts that have a deadline in the future. (current tick granularity is 1ms).
func NewTimeoutWheel ¶
func NewTimeoutWheel(options ...Option) *TimeoutWheel
NewTimeoutWheel creates and starts a new TimeoutWheel collection.
func (*TimeoutWheel) Schedule ¶
func (t *TimeoutWheel) Schedule( d time.Duration, expireCb func(interface{}), arg interface{}, ) (Timeout, error)
Schedule adds a new function to be called after some duration of time has elapsed. The returned Timeout can be used to cancel calling the function. If the duration falls between two ticks, the latter tick is used.
func (*TimeoutWheel) Start ¶
func (t *TimeoutWheel) Start()
Start starts a stopped timeout wheel. Subsequent calls to Start panic.
func (*TimeoutWheel) Stop ¶
func (t *TimeoutWheel) Stop()
Stop stops tick processing, and deletes any remaining timeouts.