1 Star 0 Fork 0

Gitee Go / utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
timer.go 519 Bytes
一键复制 编辑 原始数据 按行查看 历史
Gitee 提交于 2021-08-31 17:37 . 1.0 release.
package utils
import "time"
type Timer struct {
tms time.Time
tmd time.Duration
}
func NewTimer(tmd time.Duration, now ...bool) *Timer {
c := &Timer{
tmd: tmd,
}
if len(now) > 0 && now[0] {
c.tms = time.Now()
}
return c
}
func (c *Timer) Tick() bool {
if time.Since(c.tms) < c.tmd {
return false
} else {
c.tms = time.Now()
return true
}
}
func (c *Timer) Reset(tmd time.Duration, now ...bool) {
c.tmd = tmd
if len(now) > 0 && now[0] {
c.tms = time.Now()
} else {
c.tms = time.Time{}
}
}
1
https://gitee.com/gitee-go/utils.git
git@gitee.com:gitee-go/utils.git
gitee-go
utils
utils
main

搜索帮助