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

Golang 版本时间轮定时器

  •  
  •   orderc · 2017-06-08 23:11:23 +08:00 · 2914 次点击
    这是一个创建于 2520 天前的主题,其中的信息可能已经有所发展或是发生改变。

    项目地址

    
    package main
    
    import (
        "github.com/ouqiang/timewheel"
        "time"
        "fmt"
    )
    
    func main()  {
        // tick 刻度为 1 秒, 3600 个槽, 执行的 job
        tw := timewheel.New(1 * time.Second, 3600, func(data []interface{}) {
            fmt.Println(data)
            // do something
        })
        tw.Start()
        tw.Add(5 * time.Second, []interface{}{1})
        tw.Add(10 * time.Minute, []interface{}{2})
        tw.Add(35 * time.Hour, []interface{}{3})
        // 停止
        tw.Stop()
    }
    
    2 条回复    2017-06-10 13:15:17 +08:00
    timothyye
        1
    timothyye  
       2017-06-10 12:58:36 +08:00 via Android
    刻度和槽是什么意思?
    orderc
        2
    orderc  
    OP
       2017-06-10 13:15:17 +08:00 via iPhone   ❤️ 1
    @timothyye 手机上回复不方便,参考这篇文章,http://m.blog.csdn.net/article/details?id=52420300
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2192 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:17 · PVG 19:17 · LAX 04:17 · JFK 07:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.