mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-21 04:04:43 +08:00
新增定时器
This commit is contained in:
25
util/Timer.go
Normal file
25
util/Timer.go
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user