Documentation
¶
Index ¶
- type FuncJob
- type Job
- type Level
- type ShardedWheel
- func (sw *ShardedWheel) AddJobByInt(id int64, delay time.Duration, job Job) *Timer
- func (sw *ShardedWheel) AddJobByString(key string, delay time.Duration, job Job) *Timer
- func (sw *ShardedWheel) AddJobFuncByInt(id int64, delay time.Duration, f func()) *Timer
- func (sw *ShardedWheel) AddJobFuncByString(key string, delay time.Duration, f func()) *Timer
- func (sw *ShardedWheel) AddJobFuncRandom(delay time.Duration, f func()) *Timer
- func (sw *ShardedWheel) AddJobRandom(delay time.Duration, job Job) *Timer
- func (sw *ShardedWheel) Start()
- func (sw *ShardedWheel) Stop()
- type Timer
- type Wheel
- func (w *Wheel) AddJob(delay time.Duration, job Job) *Timer
- func (w *Wheel) AddJobFunc(delay time.Duration, f func()) *Timer
- func (w *Wheel) RemoveJob(t *Timer)
- func (w *Wheel) Schedule(interval time.Duration, job Job) *Timer
- func (w *Wheel) ScheduleFunc(interval time.Duration, f func()) *Timer
- func (w *Wheel) Start()
- func (w *Wheel) Stop()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ShardedWheel ¶
type ShardedWheel struct {
// contains filtered or unexported fields
}
func NewSharded ¶
func NewSharded(shardCount int, tick time.Duration, wheelSize, levelCount int) *ShardedWheel
Example ¶
package main
import (
"time"
fastwheel "github.com/tophgg/fast-timingwheel"
)
func main() {
stw := fastwheel.NewSharded(8, 10*time.Millisecond, 20, 3)
stw.Start()
defer stw.Stop()
userIds := []int64{1001, 1002, 1003}
for _, uid := range userIds {
stw.AddJobFuncByInt(uid, 50*time.Millisecond, func() {
// fmt.Printf("User %d timeout\n", uid)
})
}
time.Sleep(100 * time.Millisecond)
}
Output:
func (*ShardedWheel) AddJobByInt ¶
func (*ShardedWheel) AddJobByString ¶
func (*ShardedWheel) AddJobFuncByInt ¶
func (sw *ShardedWheel) AddJobFuncByInt(id int64, delay time.Duration, f func()) *Timer
func (*ShardedWheel) AddJobFuncByString ¶
func (sw *ShardedWheel) AddJobFuncByString(key string, delay time.Duration, f func()) *Timer
func (*ShardedWheel) AddJobFuncRandom ¶
func (sw *ShardedWheel) AddJobFuncRandom(delay time.Duration, f func()) *Timer
func (*ShardedWheel) AddJobRandom ¶
func (sw *ShardedWheel) AddJobRandom(delay time.Duration, job Job) *Timer
func (*ShardedWheel) Start ¶
func (sw *ShardedWheel) Start()
func (*ShardedWheel) Stop ¶
func (sw *ShardedWheel) Stop()
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
func (*Timer) GetExpiration ¶
type Wheel ¶
type Wheel struct {
// contains filtered or unexported fields
}
func New ¶
Example ¶
package main
import (
"fmt"
"time"
fastwheel "github.com/tophgg/fast-timingwheel"
)
func main() {
tw := fastwheel.New(10*time.Millisecond, 20, 3)
tw.Start()
defer tw.Stop()
c := make(chan string)
tw.AddJobFunc(50*time.Millisecond, func() {
c <- "Hello World"
})
fmt.Println(<-c)
timer := tw.ScheduleFunc(100*time.Millisecond, func() {
fmt.Println("Tick")
})
time.Sleep(390 * time.Millisecond)
timer.Stop()
}
Output: Hello World Tick Tick Tick
Click to show internal directories.
Click to hide internal directories.