Documentation
¶
Overview ¶
Package clock is the module's one time port: the current time, one-shot timers and tickers behind an interface, so that a test can drive every interval of the stack — MRP retransmission, the acknowledgement pump, the subscription reporting loop, commissioning windows, cluster timers — by hand instead of waiting for the wall clock.
Every package of the module takes its time from here: nothing outside this package calls time.Now, time.AfterFunc, time.NewTimer, time.NewTicker, time.Sleep, time.After, time.Tick, time.Since or time.Until in production code (clock/noraw_test.go fails the build on one). System is the standard library and the default of every owner; github.com/SukramJ/go-fabric/clock/clocktest.Fake is the test clock.
A host injects a clock through the owner's configuration — the `Clock clock.Clock` field of github.com/SukramJ/go-fabric/node.Config, github.com/SukramJ/go-fabric/bridge.Config and the other owners. A nil clock is System. A node hands its clock on to the bridge, the store's persist loop, OTA and mDNS, so one field moves the whole device side.
Clock.AfterFunc runs f in its own goroutine, as time.AfterFunc does; f must not assume it runs on the goroutine that armed the timer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func After ¶
After is c.NewTimer(d).C(), time.After on c. The timer is not stopped when the caller stops waiting; use Clock.NewTimer where that matters.
Types ¶
type Clock ¶
type Clock interface {
// Now is the current time.
Now() time.Time
// AfterFunc calls f in its own goroutine once d has elapsed. The
// returned Timer's C is nil.
AfterFunc(d time.Duration, f func()) Timer
// NewTimer sends the current time on the Timer's C once d has elapsed.
NewTimer(d time.Duration) Timer
// NewTicker sends the current time on the Ticker's C every d. d must
// be greater than zero.
NewTicker(d time.Duration) Ticker
}
Clock is a time source: the current time, one-shot timers and tickers. Its methods are safe for concurrent use.
type System ¶
type System struct{}
System is the Clock of the time package. Its zero value is ready.
type Ticker ¶
type Ticker interface {
// Stop turns the ticker off; no more ticks are sent.
Stop()
// Reset stops the ticker and restarts it with period d.
Reset(d time.Duration)
// C is the channel the ticks are delivered on.
C() <-chan time.Time
}
Ticker is a periodic ticker a Clock started, with time.Ticker's semantics: a slow receiver misses ticks rather than queueing them.
type Timer ¶
type Timer interface {
// Stop prevents the timer from firing. It reports whether it did:
// false means the timer had already fired or been stopped.
Stop() bool
// Reset re-arms the timer to fire after d. It reports whether the
// timer had been active.
Reset(d time.Duration) bool
// C is the channel a timer from [Clock.NewTimer] delivers on; nil for
// a timer from [Clock.AfterFunc].
C() <-chan time.Time
}
Timer is a one-shot timer a Clock started. Its semantics are those of time.Timer since Go 1.23: after Stop or Reset returns, no stale value is received from C.