Documentation
¶
Index ¶
- type Clock
- func (o *Clock) AfterFunc(d time.Duration, f func()) clocks.StopTimer
- func (o *Clock) ContextWithDeadline(ctx context.Context, t time.Time) (context.Context, context.CancelFunc)
- func (o *Clock) ContextWithDeadlineCause(ctx context.Context, t time.Time, cause error) (context.Context, context.CancelFunc)
- func (o *Clock) ContextWithTimeout(ctx context.Context, d time.Duration) (context.Context, context.CancelFunc)
- func (o *Clock) ContextWithTimeoutCause(ctx context.Context, d time.Duration, cause error) (context.Context, context.CancelFunc)
- func (o *Clock) NewTimer(d time.Duration) clocks.Timer
- func (o *Clock) Now() time.Time
- func (o *Clock) SleepFor(ctx context.Context, dur time.Duration) bool
- func (o *Clock) SleepUntil(ctx context.Context, until time.Time) bool
- func (o *Clock) Until(t time.Time) time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock wraps another clock, adjusting time intervals by adding a constant offset. (useful for simulating clock-skew) Note that relative durations are unaffected.
func NewOffsetClock ¶
NewOffsetClock creates an OffsetClock. offset is added to all absolute times.
func (*Clock) AfterFunc ¶ added in v1.1.0
AfterFunc executes function f after duration d, (delegating to the wrapped clock, as the time-argument is relative).
func (*Clock) ContextWithDeadline ¶ added in v1.2.0
func (o *Clock) ContextWithDeadline(ctx context.Context, t time.Time) (context.Context, context.CancelFunc)
ContextWithDeadline behaves like context.WithDeadline, but it uses the clock to determine the when the deadline has expired.
func (*Clock) ContextWithDeadlineCause ¶ added in v1.2.0
func (o *Clock) ContextWithDeadlineCause(ctx context.Context, t time.Time, cause error) (context.Context, context.CancelFunc)
ContextWithDeadlineCause behaves like context.WithDeadlineCause, but it uses the clock to determine the when the deadline has expired. Cause is ignored in Go 1.20 and earlier.
func (*Clock) ContextWithTimeout ¶ added in v1.2.0
func (o *Clock) ContextWithTimeout(ctx context.Context, d time.Duration) (context.Context, context.CancelFunc)
ContextWithTimeout behaves like context.WithTimeout, but it uses the clock to determine the when the timeout has elapsed.
func (*Clock) ContextWithTimeoutCause ¶ added in v1.2.0
func (o *Clock) ContextWithTimeoutCause(ctx context.Context, d time.Duration, cause error) (context.Context, context.CancelFunc)
ContextWithTimeoutCause behaves like context.WithTimeoutCause, but it uses the clock to determine the when the timeout has elapsed. Cause is ignored in Go 1.20 and earlier.
func (*Clock) NewTimer ¶ added in v1.3.0
NewTimer returns a timer from the wrapped clock's clocks.Clock.NewTimer.
func (*Clock) Now ¶
Now implements Clock, returning the current time (according to the captive clock adjusted by offset).
func (*Clock) SleepFor ¶
SleepFor is the relative-time equivalent of SleepUntil. Return value is false if context-cancellation/expiry prompted an early return.
func (*Clock) SleepUntil ¶
SleepUntil blocks until either ctx expires or until arrives. Return value is false if context-cancellation/expiry prompted an early return.