爱意满满的作品展示区。
zhengji

goTimeWheel 一个时间轮库的实现

  •  1
     
  •   zhengji ·
    zheng-ji · Oct 11, 2019 · 3339 views
    This topic created in 2441 days ago, the information mentioned may be changed or developed.

    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 replies    2019-10-12 08:06:44 +08:00
    wueizzz
        1
    wueizzz  
       Oct 11, 2019 via Android
    巧了,今天刚在 github 搜到时间轮的另一个实现
    Leigg
        2
    Leigg  
       Oct 12, 2019 via Android
    今天用下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2858 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 15:07 · PVG 23:07 · LAX 08:07 · JFK 11:07
    ♥ Do have faith in what you're doing.