timewheel

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func WithBucketsExponent(bucketExp uint) Option

WithBucketsExponent sets the number of buckets in the hash table.

func WithLocksExponent

func WithLocksExponent(lockExp uint) Option

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

func WithTickInterval(interval time.Duration) Option

WithTickInterval sets the frequency of ticks.

type Timeout

type Timeout struct {
	// contains filtered or unexported fields
}

Timeout represents a single timeout function pending expiration.

func (*Timeout) Stop

func (t *Timeout) Stop() bool

Stop stops the scheduled timeout so that the callback will not be called. It returns true if it successfully canceled

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL