From 034ac53db3e1647601fdf9c439e1499fac0329dc Mon Sep 17 00:00:00 2001 From: boyce Date: Fri, 22 Feb 2019 18:26:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=9A=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/Timer.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 util/Timer.go diff --git a/util/Timer.go b/util/Timer.go new file mode 100644 index 0000000..0d175a6 --- /dev/null +++ b/util/Timer.go @@ -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 +}