clock

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package clock provides tools for accessing time functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithClock

func WithClock(parent context.Context, clock Clock) context.Context

WithClock wraps parent in a new context with Clock

Types

type Clock

type Clock interface {
	Now() time.Time
	Since(t time.Time) time.Duration
	Until(t time.Time) time.Duration

	Sleep(d time.Duration)

	Timer(d time.Duration) Timer
	After(d time.Duration) <-chan time.Time
	AfterFunc(d time.Duration, f func()) Timer

	Ticker(d time.Duration) Ticker

	WithDeadline(parent context.Context, deadline time.Time) (context.Context, context.CancelFunc)
	WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
}

Clock is an interface for accessing time functions

func FromContext

func FromContext(ctx context.Context) Clock

FromContext returns Clock from context

type Ticker

type Ticker interface {
	C() <-chan time.Time
	Stop()
	Reset(d time.Duration)
}

Ticker is a time.Ticker interface

type Timer

type Timer interface {
	C() <-chan time.Time
	Stop() bool
	Reset(d time.Duration) bool
}

Timer is a time.Timer interface

Jump to

Keyboard shortcuts

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