gds

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: MIT Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeWheelArgument      = errors.New("incorrect task argument")
	ErrTimeWheelArgumentDelay = errors.New("parameter 'delay' must be large than zero")
	ErrTimeWheelStop          = errors.New("time wheel is stopped")
)

Functions

func Ptr added in v0.2.3

func Ptr[T any](i T) *T

Ptr returns a pointer to the given value.

Types

type TimeWheel

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

A TimeWheel is a time wheel object to schedule tasks.

func NewTimeWheel

func NewTimeWheel(interval time.Duration, slotNum uint16) (*TimeWheel, error)

NewTimeWheel create a new time wheel with the given interval and slot number.

once the time wheel is created, it will start to run tasks in a goroutine.

func (*TimeWheel) AddTask

func (tw *TimeWheel) AddTask(data interface{}, delay time.Duration, callback TimeWheelTaskCallback) (taskID interface{}, err error)

AddTask add a task to the time wheel, return the task id

func (*TimeWheel) AddTimer

func (tw *TimeWheel) AddTimer(taskID, data interface{}, delay time.Duration, callback TimeWheelTaskCallback) error

AddTimer add a timer task, if task id exists, do reset operator

func (*TimeWheel) RemoveTask

func (tw *TimeWheel) RemoveTask(taskID interface{}) error

func (*TimeWheel) ResetTask

func (tw *TimeWheel) ResetTask(taskID interface{}, delay time.Duration) error

ResetTask reset timer by the given key to the given delay.

func (*TimeWheel) Stop

func (tw *TimeWheel) Stop()

Stop stops the time wheel.

type TimeWheelTaskCallback

type TimeWheelTaskCallback func(taskID interface{}, data interface{})

TimeWheelTaskCallback defined the method to run task while timeout.

Jump to

Keyboard shortcuts

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