timewheel

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option added in v0.0.4

type Option func(*TimeWheel) error

func WithGoPool added in v0.0.4

func WithGoPool(goPool *gopool.GoroutinePool) Option

WithGoPool

@Description: 设置执行池
@param goPool
@return Option

type Task

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

func (*Task) Reset

func (t *Task) Reset()

Reset for sync.Pool

type Ticker

type Ticker struct {
	C   chan bool
	Ctx context.Context
	// contains filtered or unexported fields
}

func (*Ticker) Stop

func (t *Ticker) Stop()

type TimeWheel

type TimeWheel struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TimeWheel

@Description: 时间轮 的实现
	代码参考自 https://github.com/rfyiamcool/go-timewheel

func NewTimeWheel

func NewTimeWheel(tick time.Duration, bucketsNum int, options ...Option) (*TimeWheel, error)

NewTimeWheel create new time wheel

func (*TimeWheel) Add

func (tw *TimeWheel) Add(delay time.Duration, callback func()) *Task

Add to add a task

func (*TimeWheel) AddCron

func (tw *TimeWheel) AddCron(delay time.Duration, callback func()) *Task

AddCron add interval task

func (*TimeWheel) After

func (tw *TimeWheel) After(delay time.Duration) <-chan time.Time

func (*TimeWheel) AfterFunc

func (tw *TimeWheel) AfterFunc(delay time.Duration, callback func()) *Timer

func (*TimeWheel) NewTicker

func (tw *TimeWheel) NewTicker(delay time.Duration) *Ticker

func (*TimeWheel) NewTimer

func (tw *TimeWheel) NewTimer(delay time.Duration) *Timer

func (*TimeWheel) Remove

func (tw *TimeWheel) Remove(task *Task) error

func (*TimeWheel) Sleep

func (tw *TimeWheel) Sleep(delay time.Duration)

func (*TimeWheel) Start

func (tw *TimeWheel) Start()

Start to start the time wheel

func (*TimeWheel) Stop

func (tw *TimeWheel) Stop()

Stop to stop the time wheel

type Timer

type Timer struct {
	C chan bool

	Ctx context.Context
	// contains filtered or unexported fields
}

Timer similar to golang std timer

func (*Timer) AddStopFunc

func (t *Timer) AddStopFunc(callback func())

func (*Timer) Reset

func (t *Timer) Reset(delay time.Duration)

func (*Timer) Stop

func (t *Timer) Stop()

Jump to

Keyboard shortcuts

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