From f4272bae7c40754c3720bec7e221f95ed1cf2b86 Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 29 Oct 2024 09:59:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/time/time.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/time/time.go b/pkg/time/time.go index c50db17..0b2ed79 100644 --- a/pkg/time/time.go +++ b/pkg/time/time.go @@ -1,6 +1,7 @@ package time import ( + "sync" "time" ) @@ -41,3 +42,30 @@ func (t *Time) format() string { func (t *Time) MarshalText() ([]byte, error) { return []byte(t.format()), nil } + +func Now() Time { + return Time(time.Now()) +} + +func After(ms int64, fn func()) { + time.AfterFunc(time.Duration(ms)*time.Millisecond, fn) +} + +func Sleep(ms int64, fn func()) { + time.Sleep(time.Duration(ms) * time.Millisecond) +} + +var quick Time +var once sync.Once + +func Quick() Time { + once.Do(func() { + go func() { + for { + quick = Now() + time.Sleep(time.Second) + } + }() + }) + return quick +}