Help us shape the future of Go! Take the 2026 Go Developer Survey

clock

package
v1.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package clock 提供 lynx.Clock 的生产实现与测试用可控时钟。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Real

func Real() lynx.Clock

Real 返回真实时间源(lynx.Clock 的生产默认)。

Types

type Fake

type Fake struct {
	// contains filtered or unexported fields
}

Fake 是可控时钟:Now 返回虚拟时间;After 注册定时器;Advance 推进虚拟 时间并按 deadline 升序触发到期定时器。并发安全。

func NewFake

func NewFake(start time.Time) *Fake

NewFake 创建从 start 开始的虚拟时钟。

func (*Fake) Advance

func (f *Fake) Advance(d time.Duration) time.Time

Advance 推进虚拟时间 d,触发所有 deadline <= 新时间的定时器(按 deadline 升序;同一时刻到期的全部触发),返回推进后的时间。未到期的定时器保留。

func (*Fake) After

func (f *Fake) After(d time.Duration) <-chan time.Time

After 注册一个 d 后到期的定时器;d <= 0 立即就绪。

func (*Fake) Now

func (f *Fake) Now() time.Time

Now 返回当前虚拟时间。

func (*Fake) TimerCount

func (f *Fake) TimerCount() int

TimerCount 返回尚未触发(未到期)的定时器数:测试用它等待 loop 注册 定时器后再推进虚拟时间(消除 goroutine 调度竞态)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL