timingwheel

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed   = errors.New("TimingWheel is closed already")
	ErrArgument = errors.New("incorrect task argument")
)

Functions

This section is empty.

Types

type Execute

type Execute func(key, value any)

Execute defines the method to execute the task.

type TimingWheel

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

A TimingWheel is a timing wheel object to schedule tasks.

func NewTimingWheel

func NewTimingWheel(interval time.Duration, numSlots int, execute Execute) (*TimingWheel, error)

NewTimingWheel returns a TimingWheel.

func NewTimingWheelWithTicker

func NewTimingWheelWithTicker(interval time.Duration, numSlots int, execute Execute,
	ticker timex.Ticker) (*TimingWheel, error)

NewTimingWheelWithTicker returns a TimingWheel with the given ticker.

func (*TimingWheel) Drain

func (tw *TimingWheel) Drain(fn func(key, value any)) error

Drain drains all items and executes them.

func (*TimingWheel) MoveTimer

func (tw *TimingWheel) MoveTimer(key any, delay time.Duration) error

MoveTimer moves the task with the given key to the given delay.

func (*TimingWheel) RemoveTimer

func (tw *TimingWheel) RemoveTimer(key any) error

RemoveTimer removes the task with the given key.

func (*TimingWheel) SetTimer

func (tw *TimingWheel) SetTimer(key, value any, delay time.Duration) error

SetTimer sets the task value with the given key to the delay.

func (*TimingWheel) Stop

func (tw *TimingWheel) Stop()

Stop stops tw. No more actions after stopping a TimingWheel.

Jump to

Keyboard shortcuts

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