hourglass

package
v0.0.0-...-7c5168d Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2013 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Advance

func Advance(t *testing.T, d time.Duration)

Advance the sandbox time by the duration d. It will panic if it is not called in sandbox mode.

func After

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

After waits for the duration to elapse and then sends the current time on the returned channel, and is a replacement of time.After. It is equivalent to NewTimer(d).C.

func InitSandboxBench

func InitSandboxBench(_ *testing.B, start time.Time)

InitSandboxBench initializes the sandbox mode in benchmarks with a given start time.

func InitSandboxTest

func InitSandboxTest(_ *testing.T, start time.Time)

InitSandboxTest initializes the sandbox mode in tests with a given start time.

func Now

func Now() time.Time

Now returns the current local time, and is a replacement for time.Now. Sandbox time when in sandbox mode; system time otherwise.

func RealSleep

func RealSleep(t *testing.T, d time.Duration)

RealSleep always pauses the current goroutine for duration d at system level. It will panic if it is not called in sandbox mode.

func Since

func Since(t time.Time) time.Duration

Since returns the time elapsed since t, and is a replacement for time.Since. It is shorthand for hourglass.Now().Sub(t).

func Sleep

func Sleep(d time.Duration)

Sleep pauses the current goroutine for the duration d, and is a replacement for time.Sleep.

func Tick

func Tick(d time.Duration) <-chan time.Time

Tick is a convenience wrapper for NewTicker providing access to the ticking channel only, and is a replacement of time.Tick. Useful for clients that have no need to shut down the ticker.

Types

type Ticker

type Ticker struct {
	C <-chan time.Time // The channel on which the ticks are delivered
	// contains filtered or unexported fields
}

Ticker holds a channel that delivers ticks of a clock at intervals, and is a replacement of time.Ticker.

func NewTicker

func NewTicker(d time.Duration) *Ticker

NewTicker returns a new Ticker containing a channel that will send the time with a period specified by the duration argument, and is a replacement of time.NewTicker. It adjusts the intervals or drops ticks to make up for slow receivers. The duration d must be greater than zero; if not, NewTicker will panic.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop turns off a ticker. After being stopped, it will not send more ticks. Stop does not close the channel, to prevent a read from the channel succeeding. It is a replacement of time.Ticker.Stop.

type Timer

type Timer struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

Timer represents a system time.Timer, or a sandboxTimer. When the Timer expires, the current time will be sent on C, unless the Timer was created by AfterFunc.

func AfterFunc

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

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

func NewTimer

func NewTimer(d time.Duration) *Timer

NewTimer creats a new Timer that will send the current time on its channel after at least duration d, and is a replacement of time.NewTimer.

func (*Timer) Reset

func (t *Timer) Reset(d time.Duration) bool

Reset changes the timer to expire after duration d, which is a replacement of time.Timer.Reset. It returns true if the timer had been active, false if the timer had expired or been fired.

func (*Timer) Stop

func (t *Timer) Stop() bool

Stop prevents the Timer from firing, and is a replacement of time.Timer.Stop. It return true if the call stops the timer, false if the timer has already expired or been stopped. Stop does not close the channel, to prevent a read from the channel succeeding incorrectly.

Jump to

Keyboard shortcuts

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