clock

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 2 Imported by: 1

README

clock-go

PkgGoDev GoReportCard

Go SDK with interfaces for clocks and time keeping.

Documentation

Overview

Package clock provides primitives for mocking time.

Package clock provides interfaces and primitives for clocks and time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// After waits for the duration to elapse and then sends the current time on the returned channel.
	After(duration time.Duration) <-chan time.Time

	// AfterFunc waits for the duration to elapse and then calls the function f given to it.
	AfterFunc(d time.Duration, f func()) Timer

	// NewTicker returns a new Ticker.
	NewTicker(d time.Duration) Ticker

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

	// NowProto returns a new Protobuf timestamp representing the current local time.
	NowProto() *timestamppb.Timestamp

	// Since returns the time elapsed since t.
	Since(t time.Time) time.Duration

	// 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)
}

Clock provides capabilities from the time standard library package.

type Ticker

type Ticker interface {
	// C returns the channel on which the ticks are delivered.
	C() <-chan time.Time

	// Stop the Ticker.
	Stop()

	// Reset stops the trigger and next trigger will after the newly given duration has passed.
	Reset(duration time.Duration)
}

Ticker wraps the time.Ticker class.

type Timer

type Timer interface {
	// C returns the channel on which the timer is going to be triggered.
	C() <-chan time.Time

	// Stop the Timer.
	Stop() bool
}

Directories

Path Synopsis
Package externalclock provides a clock implementation for external time sources.
Package externalclock provides a clock implementation for external time sources.
Package systemclock provides a clock implementation for the system clock.
Package systemclock provides a clock implementation for the system clock.

Jump to

Keyboard shortcuts

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