Is there a way to do repetitive tasks at intervals?

后端 未结 7 2032
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 04:42

Is there a way to do repetitive background tasks in Go? I\'m thinking of something like Timer.schedule(task, delay, period) in Java. I know I can do this with

相关标签:
7条回答
  • 2020-12-04 05:45

    Check out this library: https://github.com/robfig/cron

    Example as below:

    c := cron.New()
    c.AddFunc("0 30 * * * *", func() { fmt.Println("Every hour on the half hour") })
    c.AddFunc("@hourly",      func() { fmt.Println("Every hour") })
    c.AddFunc("@every 1h30m", func() { fmt.Println("Every hour thirty") })
    c.Start()
    
    0 讨论(0)
提交回复
热议问题