goTimeWheel 一个时间轮库的实现

2019-10-11 17:49:52 +08:00
 zhengji

goTimeWheel

TimeWheel Implemented By Go. Go 实现的时间轮,俗称定时器

Feature

Installation

go get github.com/zheng-ji/goTimeWheel

Example

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 {}
}

License

Copyright (c) 2019 by zheng-ji released under MIT License.

2275 次点击
所在节点    分享创造
2 条回复
wueizzz
2019-10-11 21:08:46 +08:00
巧了,今天刚在 github 搜到时间轮的另一个实现
Leigg
2019-10-12 08:06:44 +08:00
今天用下

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/608339

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX