clock

package
v0.23.3 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	PassiveClock
	After(time.Duration) <-chan time.Time
	AfterFunc(time.Duration, func()) Timer
	NewTimer(time.Duration) Timer
	Sleep(time.Duration)
	NewTicker(time.Duration) Ticker
}

Clock allows for injecting fake or real clocks into code that needs to do arbitrary things based on time.

type FakeClock

type FakeClock struct {
	FakePassiveClock
	// contains filtered or unexported fields
}

FakeClock implements Clock, but returns an arbitrary time.

func NewFakeClock

func NewFakeClock(t time.Time) *FakeClock

NewFakeClock returns a new FakeClock

func (*FakeClock) After

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

After is the Fake version of time.After(d).

func (*FakeClock) AfterFunc added in v0.21.0

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

AfterFunc is the Fake version of time.AfterFunc(d, callback).

func (*FakeClock) HasWaiters

func (f *FakeClock) HasWaiters() bool

HasWaiters returns true if After or AfterFunc has been called on f but not yet satisfied (so you can write race-free tests).

func (*FakeClock) NewTicker

func (f *FakeClock) NewTicker(d time.Duration) Ticker

NewTicker returns a new Ticker.

func (*FakeClock) NewTimer

func (f *FakeClock) NewTimer(d time.Duration) Timer

NewTimer is the Fake version of time.NewTimer(d).

func (*FakeClock) SetTime

func (f *FakeClock) SetTime(t time.Time)

SetTime sets the time on a FakeClock.

func (*FakeClock) Sleep

func (f *FakeClock) Sleep(d time.Duration)

Sleep pauses the FakeClock for duration d.

func (*FakeClock) Step

func (f *FakeClock) Step(d time.Duration)

Step moves clock by Duration, notifies anyone that's called After, Tick, or NewTimer

type FakePassiveClock added in v0.16.4

type FakePassiveClock struct {
	// contains filtered or unexported fields
}

FakePassiveClock implements PassiveClock, but returns an arbitrary time.

func NewFakePassiveClock added in v0.16.4

func NewFakePassiveClock(t time.Time) *FakePassiveClock

NewFakePassiveClock returns a new FakePassiveClock.

func (*FakePassiveClock) Now added in v0.16.4

func (f *FakePassiveClock) Now() time.Time

Now returns f's time.

func (*FakePassiveClock) SetTime added in v0.16.4

func (f *FakePassiveClock) SetTime(t time.Time)

SetTime sets the time on the FakePassiveClock.

func (*FakePassiveClock) Since added in v0.16.4

func (f *FakePassiveClock) Since(ts time.Time) time.Duration

Since returns time since the time in f.

type IntervalClock

type IntervalClock struct {
	Time     time.Time
	Duration time.Duration
}

IntervalClock implements Clock, but each invocation of Now steps the clock forward the specified duration

func (*IntervalClock) After

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

After is currently unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.

func (*IntervalClock) AfterFunc added in v0.21.0

func (*IntervalClock) AfterFunc(d time.Duration, cb func()) Timer

AfterFunc is currently unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.

func (*IntervalClock) NewTicker

func (*IntervalClock) NewTicker(d time.Duration) Ticker

NewTicker is currently unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.

func (*IntervalClock) NewTimer

func (*IntervalClock) NewTimer(d time.Duration) Timer

NewTimer is currently unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.

func (*IntervalClock) Now

func (i *IntervalClock) Now() time.Time

Now returns i's time.

func (*IntervalClock) Since

func (i *IntervalClock) Since(ts time.Time) time.Duration

Since returns time since the time in i.

func (*IntervalClock) Sleep

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

Sleep is currently unimplemented; will panic.

type PassiveClock added in v0.16.4

type PassiveClock interface {
	Now() time.Time
	Since(time.Time) time.Duration
}

PassiveClock allows for injecting fake or real clocks into code that needs to read the current time but does not support scheduling activity in the future.

type RealClock

type RealClock struct{}

RealClock really calls time.Now()

func (RealClock) After

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

After is the same as time.After(d).

func (RealClock) AfterFunc added in v0.21.0

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

AfterFunc is the same as time.AfterFunc(d, f).

func (RealClock) NewTicker

func (RealClock) NewTicker(d time.Duration) Ticker

NewTicker returns a new Ticker.

func (RealClock) NewTimer

func (RealClock) NewTimer(d time.Duration) Timer

NewTimer returns a new Timer.

func (RealClock) Now

func (RealClock) Now() time.Time

Now returns the current time.

func (RealClock) Since

func (RealClock) Since(ts time.Time) time.Duration

Since returns time since the specified timestamp.

func (RealClock) Sleep

func (RealClock) Sleep(d time.Duration)

Sleep pauses the RealClock for duration d.

type Ticker

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

Ticker defines the Ticker interface

type Timer

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

Timer allows for injecting fake or real timers into code that needs to do arbitrary things based on time.

Jump to

Keyboard shortcuts

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