Skip to content

Commit

Permalink
小改动
Browse files Browse the repository at this point in the history
  • Loading branch information
zgwit committed Oct 29, 2024
1 parent e814cf5 commit f4272ba
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/time/time.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package time

import (
"sync"
"time"
)

Expand Down Expand Up @@ -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
}

0 comments on commit f4272ba

Please sign in to comment.