offset

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

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

func NewOffsetClock(inner clocks.Clock, offset time.Duration) *Clock

NewOffsetClock creates an OffsetClock. offset is added to all absolute times.

func (*Clock) AfterFunc added in v1.1.0

func (o *Clock) AfterFunc(d time.Duration, f func()) clocks.StopTimer

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

func (o *Clock) NewTimer(d time.Duration) clocks.Timer

NewTimer returns a timer from the wrapped clock's clocks.Clock.NewTimer.

func (*Clock) Now

func (o *Clock) Now() time.Time

Now implements Clock, returning the current time (according to the captive clock adjusted by offset).

func (*Clock) SleepFor

func (o *Clock) SleepFor(ctx context.Context, dur time.Duration) bool

SleepFor is the relative-time equivalent of SleepUntil. Return value is false if context-cancellation/expiry prompted an early return.

func (*Clock) SleepUntil

func (o *Clock) SleepUntil(ctx context.Context, until time.Time) bool

SleepUntil blocks until either ctx expires or until arrives. Return value is false if context-cancellation/expiry prompted an early return.

func (*Clock) Until

func (o *Clock) Until(t time.Time) time.Duration

Until implements Clock, returning the difference between the current time and its argument (according to the captive clock adjusted by offset).

Jump to

Keyboard shortcuts

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