新增定时器

This commit is contained in:
boyce
2019-02-22 18:26:05 +08:00
parent f1768ee7ec
commit 034ac53db3

25
util/Timer.go Normal file
View File

@@ -0,0 +1,25 @@
package util
import "time"
type Timer struct {
lasttime int64
timeinterval int64
}
func (slf *Timer) SetupTimer(ms int32) {
slf.lasttime = time.Now().UnixNano()
slf.timeinterval = int64(ms) * 1e6
}
func (slf *Timer) CheckTimeOut() bool {
now := time.Now().UnixNano()
if now-slf.lasttime > slf.timeinterval {
slf.lasttime = now
return true
}
return false
}