summaryrefslogtreecommitdiff
path: root/util/fasttime.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-01-05 15:51:15 +0300
committerWolfy-J <[email protected]>2019-01-05 15:51:15 +0300
commit6f1a668f5d67bc81d1ac26be84620dc5c87e1581 (patch)
tree2208fb4c411f200e666694e35ef6eb48b3c5abc8 /util/fasttime.go
parent94f4083b1d85d0a45b48cbf80d83e3049c30096e (diff)
override config flags
Diffstat (limited to 'util/fasttime.go')
-rw-r--r--util/fasttime.go41
1 files changed, 0 insertions, 41 deletions
diff --git a/util/fasttime.go b/util/fasttime.go
deleted file mode 100644
index f1a81333..00000000
--- a/util/fasttime.go
+++ /dev/null
@@ -1,41 +0,0 @@
-package util
-
-import (
- "sync/atomic"
- "time"
-)
-
-// FastTime provides current unix time using specified resolution with reduced number of syscalls.
-type FastTime struct {
- last int64
- ticker *time.Ticker
-}
-
-// NewFastTime returns new time provider with given resolution.
-func NewFastTime(resolution time.Duration) *FastTime {
- ft := &FastTime{
- last: time.Now().UnixNano(),
- ticker: time.NewTicker(resolution),
- }
-
- go ft.run()
-
- return ft
-}
-
-// Stop ticking.
-func (ft *FastTime) Stop() {
- ft.ticker.Stop()
-}
-
-// UnixNano returns current timestamps. Value might be delayed after current time by specified resolution.
-func (ft *FastTime) UnixNano() int64 {
- return atomic.LoadInt64(&ft.last)
-}
-
-// consume time values over given resolution.
-func (ft *FastTime) run() {
- for range ft.ticker.C {
- atomic.StoreInt64(&ft.last, time.Now().UnixNano())
- }
-}