timed

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

`timed` is a global `timer` instance, that tick is 1ms. wheel size is 512, use [ants](https://github.com/panjf2000/ants) goroutine pool.

Deprecated: As of v0.7.0, the same functionality is now provided by timer, and those implementations

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTask deprecated

func AddTask(task *Task) error

AddTask adds a task to the timer.

Deprecated: As of v0.7.0, use timer.AddTask instead.

func Start deprecated

func Start()

Start the timer.

Deprecated: As of v0.7.0, use timer.Start instead.

func Started deprecated

func Started() bool

Started have started or not.

Deprecated: As of v0.7.0, use timer.Started instead.

func Stop deprecated

func Stop()

Stop the timer.

Deprecated: As of v0.7.0, use timer.Stop instead.

func TaskCounter deprecated

func TaskCounter() int64

TaskCounter return the total number of tasks.

Deprecated: As of v0.7.0, use timer.TaskCounter instead.

func TickMs deprecated

func TickMs() int64

TickMs return Basic time tick milliseconds.

Deprecated: As of v0.7.0, use timer.TickMs instead.

func Timer deprecated added in v0.7.0

func Timer() *timer.Timer

Timer return the default timer.

Deprecated: As of v0.7.0, use timer.DefaultTimer instead.

Example
fmt.Println(Started())
Start()
_, _ = AfterFunc(100*time.Millisecond, func() {
	fmt.Println(100)
})
canceledTaskThenAddAgain := NewTask(1100 * time.Millisecond).WithJobFunc(func() {
	fmt.Println("canceled then add again")
})
_ = AddTask(canceledTaskThenAddAgain)
canceledTaskThenAddAgain.Cancel()
_ = AddTask(NewTask(1025 * time.Millisecond).WithJobFunc(func() {
	fmt.Println(200)
}))
_ = AddTask(canceledTaskThenAddAgain)
time.Sleep(time.Second + time.Millisecond*200)
Stop()
Output:

true
100
200
canceled then add again

func WheelSize deprecated

func WheelSize() int

WheelSize return the wheel size.

Deprecated: As of v0.7.0, use timer.WheelSize instead.

Types

type Job added in v0.5.3

type Job = timer.Job

alias

type JobFunc added in v0.5.3

type JobFunc = timer.JobFunc

alias

type Task

type Task = timer.Task

alias

func AfterFunc deprecated

func AfterFunc(d time.Duration, f func()) (*Task, error)

AfterFunc adds a function to the timer.

Deprecated: As of v0.7.0, use timer.AfterFunc instead.

func NewTask deprecated

func NewTask(d time.Duration) *Task

NewTask new task with delay duration and an empty job, the accuracy is milliseconds.

Deprecated: As of v0.7.0, use timer.NewTask instead.

func NewTaskFunc deprecated

func NewTaskFunc(d time.Duration, f func()) *Task

NewTaskFunc new task with delay duration and a function job, the accuracy is milliseconds.

Deprecated: As of v0.7.0, use timer.NewTaskFunc instead.

func NewTaskJob deprecated added in v0.5.3

func NewTaskJob(d time.Duration, j Job) *Task

NewTaskJob new task with delay duration and a job, the accuracy is milliseconds.

Deprecated: As of v0.7.0, use timer.NewTaskJob instead.

Jump to

Keyboard shortcuts

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