apimachinery: k8s.io/apimachinery/pkg/util/clock Index | Files

package clock

import "k8s.io/apimachinery/pkg/util/clock"

Index

Package Files

clock.go

type Clock Uses

type Clock interface {
    PassiveClock
    After(time.Duration) <-chan time.Time
    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 Uses

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

FakeClock implements Clock, but returns an arbitrary time.

func NewFakeClock Uses

func NewFakeClock(t time.Time) *FakeClock

func (*FakeClock) After Uses

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

Fake version of time.After(d).

func (*FakeClock) HasWaiters Uses

func (f *FakeClock) HasWaiters() bool

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

func (*FakeClock) NewTicker Uses

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

func (*FakeClock) NewTimer Uses

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

Fake version of time.NewTimer(d).

func (*FakeClock) SetTime Uses

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

Sets the time.

func (*FakeClock) Sleep Uses

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

func (*FakeClock) Step Uses

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

Move clock by Duration, notify anyone that's called After, Tick, or NewTimer

type FakePassiveClock Uses

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

FakePassiveClock implements PassiveClock, but returns an arbitrary time.

func NewFakePassiveClock Uses

func NewFakePassiveClock(t time.Time) *FakePassiveClock

func (*FakePassiveClock) Now Uses

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

Now returns f's time.

func (*FakePassiveClock) SetTime Uses

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

Sets the time.

func (*FakePassiveClock) Since Uses

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

Since returns time since the time in f.

type IntervalClock Uses

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 Uses

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

Unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.

func (*IntervalClock) NewTicker Uses

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

Unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.

func (*IntervalClock) NewTimer Uses

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

Unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.

func (*IntervalClock) Now Uses

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

Now returns i's time.

func (*IntervalClock) Since Uses

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

Since returns time since the time in i.

func (*IntervalClock) Sleep Uses

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

type PassiveClock Uses

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 Uses

type RealClock struct{}

RealClock really calls time.Now()

func (RealClock) After Uses

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

Same as time.After(d).

func (RealClock) NewTicker Uses

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

func (RealClock) NewTimer Uses

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

func (RealClock) Now Uses

func (RealClock) Now() time.Time

Now returns the current time.

func (RealClock) Since Uses

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

Since returns time since the specified timestamp.

func (RealClock) Sleep Uses

func (RealClock) Sleep(d time.Duration)

type Ticker Uses

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

type Timer Uses

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.

Package clock imports 2 packages (graph) and is imported by 126 packages. Updated 2019-08-29. Refresh now. Tools for package owners.