base-golang/pkg/downloader/util/timer.go
2024-07-31 17:02:30 +08:00

26 lines
362 B
Go

package util
import "time"
// Timer 计时器
type Timer struct {
t int64
used int64
}
func (t *Timer) Start() {
t.t = time.Now().UnixNano()
}
func (t *Timer) Pause() {
t.used += time.Now().UnixNano() - t.t
}
func (t *Timer) Continue() {
t.t = time.Now().UnixNano()
}
func (t *Timer) Used() int64 {
return (time.Now().UnixNano() - t.t) + t.used
}