timeout

package
v0.0.0-...-157c9c8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package timeout is primarily intended as a test utility. It provides the function timeout.After(ms, wait) which will wait ms number of milliseconds for the wait object.

The wait value can be a function. It will be called with no arguments. If it does not return before the timeout duration a TimeoutError is returned. If the last return value of the function is of type error and the function does not timeout but does return an error, that error will be returned.

The wait value can be a channel. If it is a send only channel, the zero value for the channel will be sent. If it blocks longer than the timeout duration, a TimeoutError is returned. If the channel can receive, it will try for the timeout duration. If it does not receive within the duration, a TimeoutError is returned. If the channel does receive but the value that comes through the channel is an interface that fulfills error and is not nil, that error value is returned.

The wait value can be a *sync.WaitGroup. It must be a pointer to a WaitGroup, passing in a WaitGroup by value causes it's Wait() method to not behave correctly.

If the wait value is not a valid type an InvalidWait error is returned.

Index

Constants

View Source
const (
	// ErrTimeout is returned when a timeout occures
	ErrTimeout = lerr.Str("timeout")

	// InvalidWaitMsg returned by timeout.InvalidWaitMsg.Error()
	InvalidWaitMsg = "expected wait to be function, got %s"
)

Variables

This section is empty.

Functions

func After

func After(ms int, wait interface{}) error

After returns Timeout when a specified number of milliseconds (ms) have passed if wait has not completed. If wait is not a valid type InvalidWait is returned.

func Must

func Must(ms int, wait interface{})

Must calls After and will panic if an error is returned.

Types

type MockTime

type MockTime struct {
	N            time.Time
	TickDuration time.Duration
	// contains filtered or unexported fields
}

func NewMockTime

func NewMockTime() *MockTime

func (*MockTime) Now

func (mt *MockTime) Now() time.Time

func (*MockTime) Sleep

func (mt *MockTime) Sleep(d time.Duration)

func (*MockTime) Tick

func (mt *MockTime) Tick(ticks int)

Jump to

Keyboard shortcuts

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