clock: github.com/101loops/clock Index | Files

package clock

import "github.com/101loops/clock"

Index

Package Files

clock.go mock.go real.go

func After Uses

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. It is equivalent to NewTimer(d).C.

func Now Uses

func Now() time.Time

Now returns the current local time.

func Sleep Uses

func Sleep(d time.Duration)

Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.

func Tick Uses

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

Tick is a convenience wrapper for NewTicker providing access to the ticking channel only.

func Ticker Uses

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

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

type Clock Uses

type Clock interface {

    // Now returns the current local time.
    Now() time.Time

    // Sleep pauses the current goroutine for at least the duration d.
    // A negative or zero duration causes Sleep to return immediately.
    Sleep(d time.Duration)

    // After waits for the duration to elapse and then sends the current time
    // on the returned channel. It is equivalent to NewTimer(d).C.
    After(d time.Duration) <-chan time.Time

    // Tick is a convenience wrapper for NewTicker providing access to the
    // ticking channel only.
    Tick(d time.Duration) <-chan time.Time

    // Ticker returns a new Ticker containing a channel that will send the
    // time with a period specified by the duration argument. It adjusts
    // the intervals or drops ticks to make up for slow receivers.
    // The duration d must be greater than zero; if not, Ticker will panic.
    Ticker(d time.Duration) *time.Ticker
}

Clock provides the functions from the time package.

var Work Clock

Work mirrors the behaviour of Go's time package.

func New Uses

func New() Clock

New returns a new Clock that mirrors the behaviour of the time package.

type Mock Uses

type Mock interface {
    Clock

    // Set applies the passed-in time to the Clock's time.
    Set(t time.Time) Mock

    // Add changes the Clock's time by the passed-in duration.
    Add(d time.Duration) Mock

    // Freeze stops the clock's time.
    Freeze() Mock

    // Freeze stops the clock's time at the passed-in moment.
    FreezeAt(t time.Time) Mock

    // IsFrozen is whether the clock's time is stopped.
    IsFrozen() bool

    // Unfreeze starts the clock's time again.
    Unfreeze() Mock

    // SetSleep overrides the passed-in argument to the Sleep method.
    SetSleep(d time.Duration) Mock

    // NoSleep disables the Sleep method.
    NoSleep() Mock

    // ResetSleep re-enables the default Sleep behaviour.
    ResetSleep() Mock
}

Mock represents a manipulable Work. It is concurrent-friendly.

func NewMock Uses

func NewMock() Mock

NewMock returns a new manipulable Clock.

Package clock imports 2 packages (graph). Updated 2018-02-27. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).