ttime

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package ttime implements a testable alternative to the Go "time" package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Now

func Now() time.Time

Now returns the implementation's current time

func SetTime

func SetTime(t Time)

SetTime configures what 'Time' implementation to use for each of the package-level methods.

func Since

func Since(t time.Time) time.Duration

Since returns the time different from Now and the given time t

Types

type DefaultTime

type DefaultTime struct{}

DefaultTime is a Time that behaves normally

func (*DefaultTime) After added in v1.1.0

func (*DefaultTime) After(d time.Duration) <-chan time.Time

After sleeps for the given duration and then writes to to the returned channel

func (*DefaultTime) AfterFunc added in v1.3.1

func (*DefaultTime) AfterFunc(d time.Duration, f func()) Timer

AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.

func (*DefaultTime) Now

func (*DefaultTime) Now() time.Time

Now returns the current time

func (*DefaultTime) Sleep

func (*DefaultTime) Sleep(d time.Duration)

Sleep sleeps for the given duration

type Time

type Time interface {
	Now() time.Time
	Sleep(d time.Duration)
	After(d time.Duration) <-chan time.Time
	AfterFunc(d time.Duration, f func()) Timer
}

Time represents an implementation for this package's methods

type Timer added in v1.3.1

type Timer interface {
	Reset(d time.Duration) bool
	Stop() bool
}

Directories

Path Synopsis
Package mock_ttime is a generated GoMock package.
Package mock_ttime is a generated GoMock package.

Jump to

Keyboard shortcuts

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