tik
July 4, 2020 ยท View on GitHub
import "github.com/andy2046/tik"
Overview
Package tik implements Hierarchical Timing Wheels.
Index
- Variables
- type Callback
- type Config
- type DefaultTimer
- type Option
- type Ticker
- type Timeout
- type Timer
Package files
bit.go ticker.go timeout.go timer.go
Variables
var (
// DefaultConfig is the default Ticker Config.
DefaultConfig = Config{
WheelBitNum: 6,
WheelNum: 4,
Timer: nil,
}
)
type Callback
type Callback func()
Callback function to trigger when timeout expires.
type Config
type Config struct {
// number of value bits mapped in each wheel.
WheelBitNum uint8
// number of wheels.
WheelNum uint8
// Timer to progress the timing wheel.
Timer Timer
}
Config used to init Ticker.
type DefaultTimer
type DefaultTimer struct {
// contains filtered or unexported fields
}
DefaultTimer implements Timer interface.
func (*DefaultTimer) Now
func (dt *DefaultTimer) Now() uint64
Now returns the absolute time when timer started in millisecond.
func (*DefaultTimer) Step
func (dt *DefaultTimer) Step() <-chan uint64
Step timing wheel by absolute time in millisecond.
func (*DefaultTimer) Stop
func (dt *DefaultTimer) Stop()
Stop the DefaultTimer.
type Option
type Option = func(*Config)
Option applies config to Ticker Config.
type Ticker
type Ticker struct {
// contains filtered or unexported fields
}
Ticker progress the timing wheels.
func New
func New(options ...Option) *Ticker
New initiates a new Ticker.
func (*Ticker) AnyExpired
func (tk *Ticker) AnyExpired() bool
AnyExpired returns true if expiry queue is not empty, false otherwise.
func (*Ticker) AnyPending
func (tk *Ticker) AnyPending() bool
AnyPending returns true if there is task in wheels, false otherwise.
func (*Ticker) Cancel
func (tk *Ticker) Cancel(to *Timeout)
Cancel the Timeout scheduled if it has not yet expired.
func (*Ticker) Close
func (tk *Ticker) Close()
Close stop processing any task, whether it is pending or expired.
func (*Ticker) IsClosed
func (tk *Ticker) IsClosed() bool
IsClosed returns true if closed, false otherwise.
func (*Ticker) Schedule
func (tk *Ticker) Schedule(delay uint64, cb Callback) *Timeout
Schedule creates a one-shot action that executed after the given delay.
delay is the time from now to delay execution,
the time unit of the delay depends on the Timer provided, default is millisecond.
cb is the task to execute.
it returns nil if Ticker is closed.
type Timeout
type Timeout struct {
// contains filtered or unexported fields
}
Timeout represents user timeout logic.
func (*Timeout) Expired
func (to *Timeout) Expired() bool
Expired returns true if timeout is in expired queue, false otherwise.
func (*Timeout) Pending
func (to *Timeout) Pending() bool
Pending returns true if timeout is in timing wheel, false otherwise.
type Timer
type Timer interface {
// Now returns the absolute time when timer started.
Now() uint64
// Step channel to step timing wheel by absolute time.
Step() <-chan uint64
// Stop the timer.
Stop()
}
Timer progress the timing wheel by current time.
func NewTimer
func NewTimer(interval uint64) Timer
NewTimer returns DefaultTimer with interval in millisecond.
Generated by godoc2md