V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
zhengji
V2EX  ?  分享创造

goTimeWheel 一个时间轮库的实现

  •  1
     
  •   zhengji ·
    zheng-ji · 2019-10-11 17:49:52 +08:00 · 2279 次点击
    这是一个创建于 1667 天前的主题,其中的信息可能已经有所发展或是发生改变。

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

    goTimeWheel

    Build Status codecov GoDoc

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

    goTimeWheel

    Feature

    • Effective at Space Usage
    • Each Timer Can Custom Its Task

    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.

    2 条回复  ?  2019-10-12 08:06:44 +08:00
    wueizzz
        1
    wueizzz  
       2019-10-11 21:08:46 +08:00 via Android
    巧了,今天刚在 github 搜到时间轮的另一个实现
    Leigg
        2
    Leigg  
       2019-10-12 08:06:44 +08:00 via Android
    今天用下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1012 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 18:26 · PVG 02:26 · LAX 11:26 · JFK 14:26
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com