Ai
1 Star 0 Fork 0

非空非零/jupiter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
time_ticker.go 586 Bytes
一键复制 编辑 原始数据 按行查看 历史
MEX7 提交于 2020-08-31 22:57 +08:00 . feat: support mongo & support sentinel
package xtime
import (
"sync/atomic"
"time"
)
var nowInMs = uint64(0)
// StartTimeTicker starts a background task that caches current timestamp per millisecond,
// which may provide better performance in high-concurrency scenarios.
func StartTimeTicker() {
atomic.StoreUint64(&nowInMs, uint64(time.Now().UnixNano())/UnixTimeUnitOffset)
go func() {
for {
now := uint64(time.Now().UnixNano()) / UnixTimeUnitOffset
atomic.StoreUint64(&nowInMs, now)
time.Sleep(time.Millisecond)
}
}()
}
func CurrentTimeMillsWithTicker() uint64 {
return atomic.LoadUint64(&nowInMs)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/nonull/eden.git
git@gitee.com:nonull/eden.git
nonull
eden
jupiter
v0.3.1

搜索帮助