timeutil

package
v3.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Now

func Now() time.Time

Now returns result of time.Now() if no TestHookTimeNow set up.

func StubTestHookNewTimer

func StubTestHookNewTimer(f func(time.Duration) Timer) (cleanup func())

StubTestHookNewTimer stubs all creation of Timers for ydb packages. It returns cleanup function that MUST be called after test execution.

NOTE: tests using this function MUST not be called concurrently.

func StubTestHookTimeNow

func StubTestHookTimeNow(now time.Time) (shifter func(time.Duration), cleanup func())

StubTestHookTimeNow stubs all `Now()` use for ydb packages.

It sets up current time to given now time. It returns time shifter function that shifts current time by given duration. It returns cleanup function that MUST be called after test execution.

NOTE: tests using this function MUST not be called concurrently.

func Until

func Until(t time.Time) time.Duration

Until returns the duration until t. It is shorthand for t.Sub(timeutil.Now()).

Types

type Timer

type Timer interface {
	Reset(time.Duration) bool
	Stop() bool
	C() <-chan time.Time
}

Timer is the interface used by node watcher to be periodically triggered to prepare some action.

func AfterFunc

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

AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.

func NewStoppedTimer

func NewStoppedTimer() Timer

NewStoppedTimer creates a new stopped Timer.

func NewTimer

func NewTimer(d time.Duration) Timer

NewTimer creates a new Timer that will send the current time on its channel after at least duration d.

It uses time package as timer implementation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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