clock

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package clock 提供可注入的时钟,便于测试定时器与历史时间。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// Now 返回当前时间。
	// @return 当前时间
	Now() time.Time
}

Clock 是时间源接口。

type Fake

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

Fake 是可控时钟,并发安全。

func NewFake

func NewFake(now time.Time) *Fake

NewFake 创建假时钟。 @param now 初始时间 @return 假时钟

func (*Fake) Advance

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

Advance 推进时间。 @param d 推进时长

func (*Fake) Now

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

Now 返回当前时间。 @return 当前时间

func (*Fake) Set

func (f *Fake) Set(t time.Time)

Set 设置时间。 @param t 新时间

type Real

type Real struct{}

Real 是真实时钟。

func (Real) Now

func (Real) Now() time.Time

Now 返回当前时间。 @return 当前时间

Jump to

Keyboard shortcuts

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