TimeWheel Implemented By Go. Go 实现的时间轮,俗称定时器
go get github.com/zheng-ji/goTimeWheel
import (
"fmt"
"github.com/zheng-ji/goTimeWheele"
)
func main() {
// timer ticker
tw := goTimeWheel.New(1*time.Second, 3600)
tw.Start()
// "ID1" means the timer's name
// Specify a function and params, it will run after 3s later
name := "ID1"
params := map[string]int{"age": 1}
fn := func(data interface{}) {
fmt.Printf("hello, %v\n", data)
}
tw.AddTimer(3*time.Second, name, fn, params)
// Your Logic Code
select {}
}
Copyright (c) 2019 by zheng-ji released under MIT License.
1
wueizzz 2019-10-11 21:08:46 +08:00 via Android
巧了,今天刚在 github 搜到时间轮的另一个实现
|
2
Leigg 2019-10-12 08:06:44 +08:00 via Android
今天用下
|