Documentation ¶
Index ¶
- Constants
- Variables
- func Days[T constraints.Integer](days T) time.Duration
- func Hour[T constraints.Integer](hours T) time.Duration
- func Milli[T constraints.Integer](msecs T) time.Duration
- func Min[T constraints.Integer](mins T) time.Duration
- func Sec[T constraints.Integer](secs T) time.Duration
- func Sleep[N constraints.Float | constraints.Integer](secs N)
- func SleepToNextSecond()
- func SleepToNextSecondsN(n int)
- func UnixFloat(t time.Time) float64
- func UpTime() time.Duration
- func Wait(f func() (done bool), interval ...time.Duration)
- type Age
- type E
- type PeriodicSleeper
- type Tick
- type TickCallback
- type TickCallbackParam
- type TimeoutCallback
- type Timer
Constants ¶
View Source
const ( // ErrTimerIsNotRunning indicates that timer is not running ErrTimerIsNotRunning = E("timer is not running") // ErrTimerIsAlreadyRunning indicates that timer is already running ErrTimerIsAlreadyRunning = E("timer is already running") )
Variables ¶
View Source
var ( // Beijing 表示北京时间 Beijing = time.FixedZone("Asia/Beijing", 8*60*60) )
Functions ¶
Types ¶
type PeriodicSleeper ¶
PeriodicSleeper 用在以下场景: 每次 sleep 结束之后, 当指定下一次 sleep 时长 T 时, 不会 完全按照 T 来 sleep, 而是参照自身上一次 sleep 的预期时间 tₙ₋₁ + T 来 sleep。这与 Tick 类似, 不同的是每次 sleep 的时间需要重新指定。
需要注意的是: 如果 tₙ₋₁ + T 小于当前时间, 则会触发一次 Reset 动作之后再 + T
func NewPeriodicSleeper ¶
func NewPeriodicSleeper() PeriodicSleeper
NewPeriodicSleeper 以当前时间新建一个 PeriodicSleeper
type Tick ¶
type Tick interface { Run() Stop() SetCallback(fn TickCallback) }
Tick 提供一个长期尽可能周期性的 tick
func NewTickBeta ¶
func NewTickBeta(interval time.Duration, callback TickCallback) (Tick, error)
NewTickBeta 新建一个 tick, 目前暂时实现毫秒级, 再低了不支持。此外, 仅支持精确到毫秒, 更低的不支持
此外, 目前理论上再高并发时会有竞争问题, 建议不要频繁创建销毁
type TickCallback ¶
type TickCallback func(param TickCallbackParam)
type TickCallbackParam ¶
type TickCallbackParam struct { }
type Timer ¶
type Timer interface { // Run starts timer in the background. Run() error // Stop stops the timer if it is running. Stop() error // Running check whether timer is running. Running() bool // Remain returns remaining time in the timer Remain() time.Duration // Elapsed returns elapsed time in the timer Elapsed() time.Duration }
Timer is re-packaged time.Timer object, but have different methods.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.