sched

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateInit      = 0
	StateScheduled = 1 // task is scheduled for execution
	StateExecuted  = 2 // a non-repeating task has already executed (or is currently executing) and has not been cancelled.
	StateCancelled = 3 // task has been cancelled (with a call to TimerTask.Cancel).
)
View Source
const (
	PendingQueueCapacity = 128  // pending add/delete
	TimeoutQueueCapacity = 1024 // pending timed-out
)

Variables

View Source
var (
	ErrExecutorClosed     = errors.New("executor is closed already")
	ErrExecutorBusy       = errors.New("executor queue is full")
	ErrExecutorNotRunning = errors.New("executor not running")
)
View Source
var ErrNoHandlers = errors.New("no handlers for command")

Functions

func DeregisterHandler added in v0.4.1

func DeregisterHandler(command int32)

func DispatchMessage added in v0.3.10

func DispatchMessage(msg *fatchoy.Message) error

func RegisterHandler added in v0.3.10

func RegisterHandler(command int32, action fatchoy.MessageHandler)

func SetPanicHandler added in v0.4.1

func SetPanicHandler(f PanicHandler)

Types

type Executor

type Executor interface {
	Start()
	Execute(r Runnable) error
	Shutdown()
}

func NewAsyncExecutor added in v0.1.20

func NewAsyncExecutor(capacity int) Executor

func NewImmediateExecutor added in v0.1.16

func NewImmediateExecutor() Executor

func NewThreadPoolExecutor added in v0.1.16

func NewThreadPoolExecutor(nWorker, capacity int) Executor

type ImmediateExecutor added in v0.1.16

type ImmediateExecutor struct {
}

func (*ImmediateExecutor) Execute added in v0.1.16

func (e *ImmediateExecutor) Execute(r Runnable) error

func (*ImmediateExecutor) Instance added in v0.1.16

func (e *ImmediateExecutor) Instance() Executor

func (*ImmediateExecutor) Shutdown added in v0.1.22

func (e *ImmediateExecutor) Shutdown()

func (*ImmediateExecutor) Start added in v0.1.22

func (e *ImmediateExecutor) Start()

type MessageDispatcher added in v0.1.9

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

消息派发

func DefaultDispatcher added in v0.2.3

func DefaultDispatcher() *MessageDispatcher

func NewMessageDispatcher added in v0.2.3

func NewMessageDispatcher() *MessageDispatcher

func (*MessageDispatcher) Deregister added in v0.4.1

func (d *MessageDispatcher) Deregister(command int32)

取消所有

func (*MessageDispatcher) DeregisterOne added in v0.2.3

func (d *MessageDispatcher) DeregisterOne(command int32, handler fatchoy.MessageHandler)

取消单个注册

func (*MessageDispatcher) Dispatch added in v0.2.3

func (d *MessageDispatcher) Dispatch(msg *fatchoy.Message) error

func (*MessageDispatcher) Register added in v0.2.3

func (d *MessageDispatcher) Register(command int32, handler fatchoy.MessageHandler)

注册一个

func (*MessageDispatcher) SetPanicHandler added in v0.2.3

func (d *MessageDispatcher) SetPanicHandler(f PanicHandler)

type PanicHandler added in v0.2.3

type PanicHandler func(*fatchoy.Message, interface{})

type Runnable

type Runnable interface {
	Run() error
}

Runnable代表一个可执行对象

type Task added in v0.1.16

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

待执行的任务

func NewTask added in v0.1.16

func NewTask(action func() error) *Task

func (*Task) Cancel added in v0.1.21

func (r *Task) Cancel() bool

func (*Task) Run added in v0.1.16

func (r *Task) Run() error

func (*Task) SetState added in v0.1.21

func (r *Task) SetState(state int32)

func (*Task) State added in v0.1.21

func (r *Task) State() int32

type ThreadPoolExecutor added in v0.1.16

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

func (*ThreadPoolExecutor) Execute added in v0.1.16

func (e *ThreadPoolExecutor) Execute(r Runnable) error

func (*ThreadPoolExecutor) Shutdown added in v0.1.20

func (e *ThreadPoolExecutor) Shutdown()

func (*ThreadPoolExecutor) Start added in v0.1.22

func (e *ThreadPoolExecutor) Start()

type Timer added in v0.1.15

type Timer interface {
	Start()

	// 关闭定时器
	Shutdown()

	// 在`timeUnits`时间后执行`r`
	RunAfter(timeUnits int, r Runnable) int

	// 每隔`interval`时间执行`r`
	RunEvery(interval int, r Runnable) int

	// 取消一个timer
	Cancel(id int) bool

	// 判断timer是否在计划中
	IsPending(id int) bool

	// 超时的待执行runner
	Chan() <-chan Runnable

	// timer数量
	Size() int
}

定时器

func NewDefaultTimerQueue added in v0.1.21

func NewDefaultTimerQueue() Timer

func NewTimerQueue added in v0.1.16

func NewTimerQueue(tickInterval, timeUnit time.Duration) Timer

type TimerQueue added in v0.1.16

type TimerQueue struct {
	C chan Runnable // 到期的定时器
	// contains filtered or unexported fields
}

最小堆实现的定时器 标准库的四叉堆实现的time.Timer已经可以满足大多数高精度的定时需求 这个实现主要是为了在大量timer的场景,把timer的压力从runtime放到应用上

func (*TimerQueue) Cancel added in v0.1.16

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

取消一个timer

func (*TimerQueue) Chan added in v0.1.20

func (s *TimerQueue) Chan() <-chan Runnable

func (*TimerQueue) IsPending added in v0.1.21

func (s *TimerQueue) IsPending(id int) bool

func (*TimerQueue) RunAfter added in v0.1.16

func (s *TimerQueue) RunAfter(timeUnits int, r Runnable) int

创建一个定时器,在`timeUnits`时间后运行`r`

func (*TimerQueue) RunEvery added in v0.1.16

func (s *TimerQueue) RunEvery(interval int, r Runnable) int

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

func (*TimerQueue) Shutdown added in v0.1.16

func (s *TimerQueue) Shutdown()

func (*TimerQueue) Size added in v0.1.16

func (s *TimerQueue) Size() int

func (*TimerQueue) Start added in v0.1.21

func (s *TimerQueue) Start()

Starts the background thread explicitly

Jump to

Keyboard shortcuts

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