gds

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 8 Imported by: 3

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.

func RandomBytes added in v0.4.3

func RandomBytes(n int) ([]byte, error)

RandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly.

func RandomString added in v0.4.3

func RandomString(length uint8) string

RandomString returns a securely generated random string.

Notice: this is method copy from Echo

Types

type KeyValue added in v0.2.6

type KeyValue struct {
	Key   string `json:"key" yaml:"key"`
	Value string `json:"value" yaml:"value"`
}

KeyValue is a key-value string pair. You can use expvar.KeyValue in advanced scenarios.

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 any, delay time.Duration, callback TimeWheelTaskCallback) (taskID any, err error)

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

func (*TimeWheel) AddTimer

func (tw *TimeWheel) AddTimer(taskID, data any, 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 any) error

func (*TimeWheel) ResetTask

func (tw *TimeWheel) ResetTask(taskID any, 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 any, data any)

TimeWheelTaskCallback defined the method to run task while timeout.

Directories

Path Synopsis
Package timeinterval is time range data structure ,many trade system has this.
Package timeinterval is time range data structure ,many trade system has this.

Jump to

Keyboard shortcuts

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