1 Star 0 Fork 0

摆渡村村长/cluster-timewheel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
timewheel_local_test.go 800 Bytes
一键复制 编辑 原始数据 按行查看 历史
package timewheel
import (
"fmt"
"testing"
"time"
)
const (
Call1 CallId = iota
Call2
Call3
)
func init() {
AddCall(Call1, func(ctx *Context) {
fmt.Println("call1", ctx.Name)
})
AddCall(Call2, func(ctx *Context) {
fmt.Println("call2", ctx.Name)
panic("run")
})
AddCall(Call3, func(ctx *Context) {
fmt.Println("call3", ctx.Name)
})
}
func TestLocal(t *testing.T) {
wheel := NewLocal(time.Second, 60)
wheel.Run()
for i := 0; i < 10; i++ {
tp := Call1
if i%2 == 0 {
tp = Call2
}
wheel.AddTimer(time.Second*time.Duration(i), fmt.Sprintf("id-%d", i), nil, tp)
}
wheel.AddTimer(time.Second*3, "1", nil, Call1)
wheel.AddTimer(time.Second*20, "7", nil, Call3)
after := time.After(time.Second * 3)
select {
case <-after:
wheel.RemoveTimer("7")
}
select {}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/burybell/cluster-timewheel.git
git@gitee.com:burybell/cluster-timewheel.git
burybell
cluster-timewheel
cluster-timewheel
master

搜索帮助