mclock

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: GPL-3.0 Imports: 3 Imported by: 2,644

Documentation

Overview

Package mclock is a wrapper for a monotonic clock source

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbsTime

type AbsTime time.Duration

AbsTime represents absolute monotonic time.

func Now

func Now() AbsTime

Now returns the current absolute monotonic time.

func (AbsTime) Add added in v1.8.14

func (t AbsTime) Add(d time.Duration) AbsTime

Add returns t + d.

type Clock added in v1.8.14

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

Clock interface makes it possible to replace the monotonic system clock with a simulated clock.

type Event added in v1.9.2

type Event interface {
	Cancel() bool
}

Event represents a cancellable event returned by AfterFunc

type Simulated added in v1.8.14

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

Simulated implements a virtual Clock for reproducible time-sensitive tests. It simulates a scheduler on a virtual timescale where actual processing takes zero time.

The virtual clock doesn't advance on its own, call Run to advance it and execute timers. Since there is no way to influence the Go scheduler, testing timeout behaviour involving goroutines needs special care. A good way to test such timeouts is as follows: First perform the action that is supposed to time out. Ensure that the timer you want to test is created. Then run the clock until after the timeout. Finally observe the effect of the timeout using a channel or semaphore.

func (*Simulated) ActiveTimers added in v1.8.14

func (s *Simulated) ActiveTimers() int

func (*Simulated) After added in v1.8.14

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

After implements Clock.

func (*Simulated) AfterFunc added in v1.9.2

func (s *Simulated) AfterFunc(d time.Duration, do func()) Event

AfterFunc implements Clock.

func (*Simulated) Now added in v1.8.14

func (s *Simulated) Now() AbsTime

Now implements Clock.

func (*Simulated) Run added in v1.8.14

func (s *Simulated) Run(d time.Duration)

Run moves the clock by the given duration, executing all timers before that duration.

func (*Simulated) Sleep added in v1.8.14

func (s *Simulated) Sleep(d time.Duration)

Sleep implements Clock.

func (*Simulated) WaitForTimers added in v1.8.14

func (s *Simulated) WaitForTimers(n int)

type SimulatedEvent added in v1.9.2

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

SimulatedEvent implements Event for a virtual clock.

func (*SimulatedEvent) Cancel added in v1.9.2

func (e *SimulatedEvent) Cancel() bool

Cancel implements Event.

type System added in v1.8.14

type System struct{}

System implements Clock using the system clock.

func (System) After added in v1.8.14

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

After implements Clock.

func (System) AfterFunc added in v1.9.2

func (System) AfterFunc(d time.Duration, f func()) Event

AfterFunc implements Clock.

func (System) Now added in v1.8.14

func (System) Now() AbsTime

Now implements Clock.

func (System) Sleep added in v1.8.14

func (System) Sleep(d time.Duration)

Sleep implements Clock.

type SystemEvent added in v1.9.2

type SystemEvent time.Timer

SystemEvent implements Event using time.Timer.

func (*SystemEvent) Cancel added in v1.9.2

func (e *SystemEvent) Cancel() bool

Cancel implements Event.

Jump to

Keyboard shortcuts

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