mclock

package
v0.0.0-...-304d09f Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 2 Imported by: 0

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 int64

AbsTime represents absolute monotonic time.

func Now

func Now() AbsTime

Now returns the current absolute monotonic time.

func (AbsTime) Add

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

Add returns t + d as absolute time.

func (AbsTime) Sub

func (t AbsTime) Sub(t2 AbsTime) time.Duration

Sub returns t - t2 as a duration.

type ChanTimer

type ChanTimer interface {
	Timer

	// The channel returned by C receives a value when the timer expires.
	C() <-chan AbsTime
	// Reset reschedules the timer with a new timeout.
	// It should be invoked only on stopped or expired timers with drained channels.
	Reset(time.Duration)
}

ChanTimer is a cancellable event created by NewTimer.

type Clock

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

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

type System

type System struct{}

System implements Clock using the system clock.

func (System) After

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

After returns a channel which receives the current time after d has elapsed.

func (System) AfterFunc

func (c System) AfterFunc(d time.Duration, f func()) Timer

AfterFunc runs f on a new goroutine after the duration has elapsed.

func (System) NewTimer

func (c System) NewTimer(d time.Duration) ChanTimer

NewTimer creates a timer which can be rescheduled.

func (System) Now

func (c System) Now() AbsTime

Now returns the current monotonic time.

func (System) Sleep

func (c System) Sleep(d time.Duration)

Sleep blocks for the given duration.

type Timer

type Timer interface {
	// Stop cancels the timer. It returns false if the timer has already
	// expired or been stopped.
	Stop() bool
}

Timer is a cancellable event created by AfterFunc.

Jump to

Keyboard shortcuts

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