awaitility

package
v0.0.0-...-fb55e59 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package awaitility provides a simple mechanism to poll for conditions with a general timeout.

It is inspired by the great jvm lib "awaitility" (see https://github.com/awaitility/awaitility)

Index

Examples

Constants

View Source
const (
	// The default poll interval (100 ms)
	DEFAULT_POLL_INTERVAL = 100 * time.Millisecond

	// The default maximum timeout (10 secs)
	DEFAULT_AT_MOST = 10 * time.Second

	// The timeout error's prefix
	TIMEOUT_ERROR = "Await condition did not return true, limit reached"
)

Variables

This section is empty.

Functions

func Await

func Await(pollInterval time.Duration, atMost time.Duration, until func() bool) error

Await calls the "until" function initially and in the specified "pollInterval" until the total time spent exceeds the "atMost" limit. In this case an error is returned. There is no way of forcing a go routine to stop, so if the "until" function is long running it will continue to run in the background, even despite the Await function exiting after the atMost timeout.

Example
err := Await(100*time.Millisecond, 1000*time.Millisecond, func() bool {
	// do a real check here, e.g. some kind of isConnected()
	return false
})

if err != nil {
	// the await condition did not become true in time
}
Output:

func AwaitBlocking

func AwaitBlocking(pollInterval time.Duration, atMost time.Duration, until func() bool) error

AwaitBlocking It runs the "until" function inforeground so if the function runs longer than the atMost timeout, await does NOT abort. This is a tradeoff to have a determined state, the downside is that the function will not time out guranteed.

func AwaitDefault

func AwaitDefault(until func() bool) error

AwaitDefault calls the "Await" function with a default pollInterval of 100 ms and a default atMost timeout of 10 seconds.

func AwaitPanic

func AwaitPanic(pollInterval time.Duration, atMost time.Duration, until func() bool)

AwaitPanic calls Await but instead of returning an error it panics.

func AwaitPanicDefault

func AwaitPanicDefault(until func() bool)

AwaitDefault calls the "Await" function with a default pollInterval of 100 ms and a default atMost timeout of 10 seconds.

func IsAwaitTimeoutError

func IsAwaitTimeoutError(err error) bool

IsAwaitTimeoutError checks if an error starts with the "TIMEOUT_ERROR" prefix.

Types

This section is empty.

Jump to

Keyboard shortcuts

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