定时器组件
gcron
定时器支持 秒 时 分 日 月 周
。
使用方式
import "github.com/camry/g/gcron"
使用实例
package main
import (
"fmt"
"time"
"github.com/camry/g/gcron"
)
func main() {
c := gcron.New(gcron.WithSeconds())
c.AddFunc("*/5 * * * * *", func() {
fmt.Println(time.Now().String())
})
c.Run()
}
// Output:
// PS E:\project\Weition\go-example> go run main.go
// 2023-05-24 15:39:20.0126443 +0800 CST m=+4.607209201
// 2023-05-24 15:39:25.0001196 +0800 CST m=+9.594667001
// 2023-05-24 15:39:30.0006484 +0800 CST m=+14.595178301