Documentation
¶
Overview ¶
Package manual provides deterministic fixed and manually advanced clocks.
Index ¶
- Variables
- type Callback
- type Clock
- func (clock *Clock) Advance(duration time.Duration) (*Waiter, error)
- func (clock *Clock) AdvanceTo(target time.Time) (*Waiter, error)
- func (clock *Clock) AfterFunc(duration time.Duration, function func()) (clockpkg.Callback, error)
- func (clock *Clock) Jump(delta time.Duration) error
- func (clock *Clock) Mark() time.Duration
- func (clock *Clock) Measure() func() time.Duration
- func (clock *Clock) NewTicker(duration time.Duration) (clockpkg.Ticker, error)
- func (clock *Clock) NewTimer(duration time.Duration) (clockpkg.Timer, error)
- func (clock *Clock) Now() time.Time
- func (clock *Clock) Shutdown() error
- func (clock *Clock) Since(start time.Time) time.Duration
- func (clock *Clock) SinceMark(mark time.Duration) time.Duration
- func (clock *Clock) Sleep(ctx context.Context, duration time.Duration) error
- func (clock *Clock) Snapshot() Snapshot
- type Fixed
- type Limits
- type Option
- type Result
- type Snapshot
- type Ticker
- type Timer
- type Waiter
Constants ¶
This section is empty.
Variables ¶
var ( // ErrActiveLimit reports exhaustion of the configured active-object budget. ErrActiveLimit = errors.New("manual clock: active object limit exceeded") // ErrWorkLimit reports exhaustion of one advancement's work budget. ErrWorkLimit = errors.New("manual clock: advancement work limit exceeded") // ErrClosed reports an operation attempted after shutdown. ErrClosed = errors.New("manual clock: closed") // ErrBackwardAdvance reports an AdvanceTo target before the current wall time. ErrBackwardAdvance = errors.New("manual clock: backward advance") // ErrInvalidLimits reports a zero or negative resource budget. ErrInvalidLimits = errors.New("manual clock: invalid limits") )
Functions ¶
This section is empty.
Types ¶
type Callback ¶
type Callback struct {
// contains filtered or unexported fields
}
Callback is a manually advanced timer callback.
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock is a concurrency-safe deterministic clock. Time changes only through Advance, AdvanceTo, or Jump. It starts no hidden goroutine.
func New ¶
New constructs a clock at an explicit wall timestamp, including time.Time{}. It preserves the location and strips any process-local monotonic reading so Jump can model wall movement independently from elapsed progress.
func (*Clock) Advance ¶
Advance moves monotonic time forward and synchronously processes every event due through the target. Callbacks run outside internal locks in deterministic timestamp and registration order.
func (*Clock) AdvanceTo ¶
AdvanceTo moves forward until target wall time. Backward wall movement must use Jump so it cannot accidentally reverse monotonic progress.
func (*Clock) AfterFunc ¶
AfterFunc schedules an owned callback. A panic is recovered and counted in the advancement Result; panic payloads are never retained.
func (*Clock) Measure ¶
Measure captures current monotonic progress and returns a concurrency-safe closure whose result is unaffected by Jump.
func (*Clock) NewTicker ¶
NewTicker creates an owned ticker. Its one-element channel drops ticks while the receiver is backpressured, matching the standard library policy.
func (*Clock) Since ¶
Since returns wall-clock subtraction against Now. Use Mark and SinceMark for elapsed measurement that must remain correct across Jump.
func (*Clock) SinceMark ¶
SinceMark returns monotonic progress since mark, independent of wall jumps.
type Fixed ¶
type Fixed struct {
// contains filtered or unexported fields
}
Fixed is an immutable wall clock.
type Limits ¶
Limits bounds scheduled objects, outstanding advancement waiters, and work processed by a Clock. MaxActive applies independently to scheduled objects and advancement waiters.
type Option ¶
type Option func(*config) error
Option configures a Clock during construction.
func WithLimits ¶
WithLimits replaces the default active-object and advancement budgets.
type Result ¶
type Result struct {
StartedAt time.Duration
EndedAt time.Duration
Triggered int
Callbacks int
Panics int
}
Result summarizes bounded work performed by one advancement.
type Ticker ¶
type Ticker struct {
// contains filtered or unexported fields
}
Ticker is a manually advanced periodic timer.