sched

package
v1.3.20 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimerPrecision    = 50   // 精度为50ms
	TimerChanCapacity = 1000 //
	TimerCapacity     = 64
)

Variables

View Source
var (
	ErrExecutorClosed = errors.New("executor is closed already")
	ErrExecutorBusy   = errors.New("executor queue is full")
)

Functions

This section is empty.

Types

type Executor

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

执行器

func NewExecutor

func NewExecutor(parentCtx context.Context, concurrency, queueSize int) *Executor

func (*Executor) Execute

func (e *Executor) Execute(r Runner) error

func (*Executor) Init

func (e *Executor) Init(parentCtx context.Context, concurrency, queueSize int)

func (*Executor) Shutdown

func (e *Executor) Shutdown()

func (*Executor) Start

func (e *Executor) Start()

func (*Executor) Stats

func (e *Executor) Stats() *stats.Stats

func (*Executor) Stop

func (e *Executor) Stop()

func (*Executor) StopAndWait

func (e *Executor) StopAndWait()

type RunFunc

type RunFunc func() error

type Runnable

type Runnable struct {
	F RunFunc
}

func (*Runnable) Run

func (r *Runnable) Run() error

type Runner

type Runner interface {
	Run() error
}

Runner是一个可执行对象

func NewRunner

func NewRunner(f RunFunc) Runner

type TimeoutScheduler

type TimeoutScheduler struct {
	C chan *timerNode // 到期的定时器
	// contains filtered or unexported fields
}

最小堆定时器

func NewTimeoutScheduler

func NewTimeoutScheduler(parentCtx context.Context) *TimeoutScheduler

func (*TimeoutScheduler) Cancel

func (s *TimeoutScheduler) Cancel(id int) bool

func (*TimeoutScheduler) Init

func (s *TimeoutScheduler) Init(parentCtx context.Context)

func (*TimeoutScheduler) RunAfter

func (s *TimeoutScheduler) RunAfter(interval int, r Runner) int

创建一个定时器,在`interval`毫秒后运行`r`

func (*TimeoutScheduler) RunAt

func (s *TimeoutScheduler) RunAt(ts int64, r Runner) int

创建一个定时器,在`ts`毫秒时间戳运行`r`

func (*TimeoutScheduler) RunEvery

func (s *TimeoutScheduler) RunEvery(interval int, r Runner) int

创建一个定时器,每隔`interval`毫秒运行一次`r`

func (*TimeoutScheduler) Shutdown

func (s *TimeoutScheduler) Shutdown()

func (*TimeoutScheduler) Start

func (s *TimeoutScheduler) Start()

func (*TimeoutScheduler) StopAndWait

func (s *TimeoutScheduler) StopAndWait()

type TimerHeap

type TimerHeap []*timerNode

func (TimerHeap) Len

func (q TimerHeap) Len() int

func (TimerHeap) Less

func (q TimerHeap) Less(i, j int) bool

func (*TimerHeap) Pop

func (q *TimerHeap) Pop() interface{}

func (*TimerHeap) Push

func (q *TimerHeap) Push(x interface{})

func (TimerHeap) Swap

func (q TimerHeap) Swap(i, j int)

Jump to

Keyboard shortcuts

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