timing

package
v0.0.0-...-680e691 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefault

func SetDefault(e Engine)

SetDefault 设置默认engine

func Stop

func Stop(timerID uint64)

Stop 关闭定时器

Types

type Callback

type Callback func()

Callback 回调函数

type Engine

type Engine interface {
	// 当前时间戳
	Now() int64
	// 启动定时器
	Start(timer Timer) bool
	// 关闭定时器
	Stop(timer Timer) bool
	// 关闭Engine
	Close() error
}

Engine 毫秒级定时器管理

func NewEngine

func NewEngine(opts ...RunOption) Engine

NewEngine 创建新Engine

type Executor

type Executor interface {
	Post(t []Timer)
	Close() error
}

Executor timer执行器,默认单独线程中执行

func NewExecutor

func NewExecutor() Executor

NewExecutor 默认调度器

type ID

type ID = uint64

ID 定时器唯一ID

func NewDelayer

func NewDelayer(delay time.Duration, cb Callback, opts ...Option) ID

NewDelayer 创建timer,delay为延迟时间

func NewTicker

func NewTicker(d time.Duration, cb Callback, opts ...Option) ID

NewTicker 启动定时器,多次执行,本次执行完后会重新注册

func NewTimer

func NewTimer(expired int64, cb Callback, opts ...Option) ID

NewTimer 启动定时器,仅执行一次

type Option

type Option func(o *Options)

type Options

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

type RunOption

type RunOption func(o *RunOptions)

type RunOptions

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

type Timer

type Timer interface {
	ID() ID
	Stop()
	Call()
}

Timer 定时器

Jump to

Keyboard shortcuts

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