clockctx

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: Apache-2.0 Imports: 6 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clock

func Clock(ctx context.Context) clock.Clock

Clock retrieves the current clock set in the context, defaulting to clock.RealClock.

func WithClock

func WithClock(ctx context.Context, c clock.Clock) context.Context

WithClock sets the given clock in the context.

func WithDeadline

func WithDeadline(ctx context.Context, d time.Time) (context.Context, context.CancelFunc)

WithDeadline behaves exactly like context.WithDeadline but uses the clock from the context, if any, to determine which clock to use for the deadline.

This function delegates to WithDeadlineOfClock and has all of the caveats associated with it.

func WithDeadlineOfClock

func WithDeadlineOfClock(ctx context.Context, c clock.Clock, d time.Time) (context.Context, context.CancelFunc)

WithDeadlineOfClock sets the given context deadline to be no later than the given time under the auspices of a particular clock.

This function delegates to context.WithDeadline if c == clock.RealClock. Otherwise, it is vastly less efficient than the standard library's context package equivalent because it does not have access to internal data associated with those contexts. In performance-sensitive applications, this function must be used with care.

This function does not set the clock in the context. To do that, use clockctx.WithDeadline(clockctx.WithClock(ctx, c), d) instead.

Note that using this method in combination with a clock that moves slower than wall time and downstream calls to the standard library context.WithDeadline/context.WithTimeout methods may result in strange, undesirable behavior.

func WithTimeout

func WithTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)

WithTimeout behaves exactly like context.WithTimeout but uses the clock from the context, if any, to determine which clock to use for the timeout.

This function delegates to WithTimeoutOfClock and has all of the caveats associated with it.

func WithTimeoutOfClock

func WithTimeoutOfClock(ctx context.Context, c clock.Clock, timeout time.Duration) (context.Context, context.CancelFunc)

WithTimeoutOfClock is equivalent to WithDeadlineOfClock(ctx, c, c.Now().Add(timeout)).

Types

This section is empty.

Jump to

Keyboard shortcuts

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