tik

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

README

tik

Documentation GitHub issues license Release


hierarchical timing wheel made easy

simplified version of timeout in Golang

for documentation, view the API reference

Documentation

Overview

Package tik implements Hierarchical Timing Wheels.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig is the default Ticker Config.
	DefaultConfig = Config{
		WheelBitNum: 6,
		WheelNum:    4,
		Timer:       nil,
	}
)

Functions

This section is empty.

Types

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.

Jump to

Keyboard shortcuts

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