package clock

Import Path
	github.com/benbjohnson/clock (on go.dev)

Dependency Relation
	imports 5 packages, and imported by 4 packages

Involved Source Files clock.go context.go
Package-Level Type Names (total 5)
/* sort by: | */
Clock represents an interface to the functions in the standard library time package. Two implementations are available in the clock package. The first is a real-time clock which simply wraps the time package's functions. The second is a mock clock which will only change when programmatically adjusted. ( Clock) After(d time.Duration) <-chan time.Time ( Clock) AfterFunc(d time.Duration, f func()) *Timer ( Clock) Now() time.Time ( Clock) Since(t time.Time) time.Duration ( Clock) Sleep(d time.Duration) ( Clock) Tick(d time.Duration) <-chan time.Time ( Clock) Ticker(d time.Duration) *Ticker ( Clock) Timer(d time.Duration) *Timer ( Clock) Until(t time.Time) time.Duration ( Clock) WithDeadline(parent context.Context, d time.Time) (context.Context, context.CancelFunc) ( Clock) WithTimeout(parent context.Context, t time.Duration) (context.Context, context.CancelFunc) *Mock Clock : github.com/hibiken/asynq/internal/timeutil.Clock Clock : github.com/pion/stun.Clock Clock : github.com/pion/stun/v3.Clock Clock : github.com/quic-go/quic-go/internal/congestion.Clock Clock : go.uber.org/dig/internal/digclock.Clock Clock : go.uber.org/fx/internal/fxclock.Clock func New() Clock func github.com/libp2p/go-flow-metrics.SetClock(c Clock) func github.com/libp2p/go-libp2p/p2p/net/connmgr.WithClock(c Clock) connmgr.Option func github.com/libp2p/go-libp2p/p2p/transport/webtransport.WithClock(cl Clock) libp2pwebtransport.Option
Re-export of time.Duration
Mock represents a mock clock that only moves forward programmically. It can be preferable to a real-time clock when testing time-based functionality. Add moves the current time of the mock clock forward by the specified duration. This should only be called from a single goroutine at a time. After waits for the duration to elapse and then sends the current time on the returned channel. AfterFunc waits for the duration to elapse and then executes a function in its own goroutine. A Timer is returned that can be stopped. Now returns the current wall time on the mock clock. Set sets the current time of the mock clock to a specific one. This should only be called from a single goroutine at a time. Since returns time since `t` using the mock clock's wall time. Sleep pauses the goroutine for the given duration on the mock clock. The clock must be moved forward in a separate goroutine. Tick is a convenience function for Ticker(). It will return a ticker channel that cannot be stopped. Ticker creates a new instance of Ticker. Timer creates a new instance of Timer. Until returns time until `t` using the mock clock's wall time. WaitForAllTimers sets the clock until all timers are expired (*Mock) WithDeadline(parent context.Context, deadline time.Time) (context.Context, context.CancelFunc) (*Mock) WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc) *Mock : Clock *Mock : github.com/hibiken/asynq/internal/timeutil.Clock *Mock : github.com/pion/stun.Clock *Mock : github.com/pion/stun/v3.Clock *Mock : github.com/quic-go/quic-go/internal/congestion.Clock *Mock : go.uber.org/dig/internal/digclock.Clock *Mock : go.uber.org/fx/internal/fxclock.Clock func NewMock() *Mock
Ticker holds a channel that receives "ticks" at regular intervals. C <-chan time.Time Reset resets the ticker to a new duration. Stop turns off the ticker. func Clock.Ticker(d time.Duration) *Ticker func (*Mock).Ticker(d time.Duration) *Ticker
Timer represents a single event. The current time will be sent on C, unless the timer was created by AfterFunc. C <-chan time.Time Reset changes the expiry time of the timer Stop turns off the ticker. *Timer : google.golang.org/grpc/internal.Timer func Clock.AfterFunc(d time.Duration, f func()) *Timer func Clock.Timer(d time.Duration) *Timer func (*Mock).AfterFunc(d time.Duration, f func()) *Timer func (*Mock).Timer(d time.Duration) *Timer
Package-Level Functions (total 2)
New returns an instance of a real-time clock.
NewMock returns an instance of a mock clock. The current time of the mock clock on initialization is the Unix epoch.