Documentation
¶
Index ¶
- Constants
- Variables
- func CompareSpoke(sp1, sp2 *Spoke) int
- func IsPowOf2(x int) bool
- func NextPowOf2(x int) int
- type GoPool
- type Job
- type JobFunc
- type Option
- type Spoke
- type Task
- type Timer
- func (t *Timer) AddTask(task *Task) error
- func (t *Timer) AfterFunc(d time.Duration, f func()) (*Task, error)
- func (t *Timer) Start()
- func (t *Timer) Started() bool
- func (t *Timer) Stop()
- func (t *Timer) TaskCounter() int64
- func (t *Timer) TickMs() int64
- func (t *Timer) WheelMask() int
- func (t *Timer) WheelSize() int
- type TimingWheel
Examples ¶
Constants ¶
View Source
const ( // DefaultTickMs default tick milliseconds. DefaultTickMs = 1 // DefaultWheelSize default wheel size. DefaultWheelSize = 512 )
Variables ¶
View Source
var ErrClosed = errors.New("timer: use of closed timer")
ErrClosed is returned when the timer is closed.
Functions ¶
func CompareSpoke ¶ added in v0.5.2
CompareSpoke compare two `Spoke` with expiration.
Types ¶
type Spoke ¶
type Spoke struct {
// contains filtered or unexported fields
}
Spoke a spoke of the wheel.
func (*Spoke) Flush ¶
func (sp *Spoke) Flush(f func(*taskEntry))
Flush all task entries and apply the supplied function to each of them
func (*Spoke) GetExpiration ¶
GetExpiration the spoke's expiration time
func (*Spoke) Remove ¶
func (sp *Spoke) Remove(te *taskEntry)
Remove the specified timer task from this list
func (*Spoke) SetExpiration ¶
SetExpiration the spoke's expiration time Returns true if the expiration time is changed
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task timer task.
func NewTaskFunc ¶
NewTaskFunc new task with delay duration and function job, the accuracy is milliseconds.
func NewTaskJob ¶ added in v0.5.2
NewTaskJob new task with delay duration and job, the accuracy is milliseconds.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer is a timer
Example ¶
tm := NewTimer()
tm.Start()
_, _ = tm.AfterFunc(100*time.Millisecond, func() {
fmt.Println(100)
})
canceledTaskThenAddAgain := NewTask(1100 * time.Millisecond).WithJobFunc(func() {
fmt.Println("canceled then add again")
})
_ = tm.AddTask(canceledTaskThenAddAgain)
canceledTaskThenAddAgain.Cancel()
_ = tm.AddTask(NewTask(1025 * time.Millisecond).WithJobFunc(func() {
fmt.Println(200)
}))
_ = tm.AddTask(canceledTaskThenAddAgain)
time.Sleep(time.Second + time.Millisecond*200)
tm.Stop()
Output: 100 200 canceled then add again
func (*Timer) Stop ¶
func (t *Timer) Stop()
Stop the timer, graceful shutdown waiting the goroutine until it's stopped.
func (*Timer) TaskCounter ¶
TaskCounter the total number of tasks.
type TimingWheel ¶
type TimingWheel struct {
// contains filtered or unexported fields
}
Directories
¶
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
monitor
command
|
|
|
repetition
command
|
|
|
sample
command
|
|
|
go
|
|
|
heap
Package heap provides heap operations for any type that implements heap.Interface.
|
Package heap provides heap operations for any type that implements heap.Interface. |
Click to show internal directories.
Click to hide internal directories.