Documentation ¶
Index ¶
- Constants
- Variables
- type Executor
- type ImmediateExecutor
- type MessageDispatcher
- func (d *MessageDispatcher) DeregisterAll(command int32)
- func (d *MessageDispatcher) DeregisterOne(command int32, handler fatchoy.PacketHandler)
- func (d *MessageDispatcher) Dispatch(pkt fatchoy.IPacket) error
- func (d *MessageDispatcher) Register(command int32, handler fatchoy.PacketHandler)
- func (d *MessageDispatcher) SetPanicHandler(action PanicHandler)
- type PanicHandler
- type Runnable
- type Task
- type ThreadPoolExecutor
- type Timer
- type TimerQueue
- func (s *TimerQueue) Cancel(id int) bool
- func (s *TimerQueue) Chan() <-chan Runnable
- func (s *TimerQueue) IsPending(id int) bool
- func (s *TimerQueue) RunAfter(timeUnits int, r Runnable) int
- func (s *TimerQueue) RunEvery(interval int, r Runnable) int
- func (s *TimerQueue) Shutdown()
- func (s *TimerQueue) Size() int
- func (s *TimerQueue) Start()
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 ¶
Functions ¶
This section is empty.
Types ¶
type Executor ¶
func NewAsyncExecutor ¶ added in v0.1.20
func NewImmediateExecutor ¶ added in v0.1.16
func NewImmediateExecutor() Executor
func NewThreadPoolExecutor ¶ added in v0.1.16
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) DeregisterAll ¶ added in v0.2.3
func (d *MessageDispatcher) DeregisterAll(command int32)
取消所有
func (*MessageDispatcher) DeregisterOne ¶ added in v0.2.3
func (d *MessageDispatcher) DeregisterOne(command int32, handler fatchoy.PacketHandler)
取消单个注册
func (*MessageDispatcher) Dispatch ¶ added in v0.2.3
func (d *MessageDispatcher) Dispatch(pkt fatchoy.IPacket) error
func (*MessageDispatcher) Register ¶ added in v0.2.3
func (d *MessageDispatcher) Register(command int32, handler fatchoy.PacketHandler)
注册一个
func (*MessageDispatcher) SetPanicHandler ¶ added in v0.2.3
func (d *MessageDispatcher) SetPanicHandler(action PanicHandler)
type PanicHandler ¶ added in v0.2.3
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
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) 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
Click to show internal directories.
Click to hide internal directories.