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

goTimeWheel 一个时间轮库的实现

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

    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   ·   我们的愿景   ·   实用小工具   ·   2883 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 07:21 · PVG 15:21 · LAX 00:21 · JFK 03:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.