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 ¶
- Constants
- func Await(pollInterval time.Duration, atMost time.Duration, until func() bool) error
- func AwaitBlocking(pollInterval time.Duration, atMost time.Duration, until func() bool) error
- func AwaitDefault(until func() bool) error
- func AwaitPanic(pollInterval time.Duration, atMost time.Duration, until func() bool)
- func AwaitPanicDefault(until func() bool)
- func IsAwaitTimeoutError(err error) bool
Examples ¶
Constants ¶
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 ¶
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 ¶
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 ¶
AwaitDefault calls the "Await" function with a default pollInterval of 100 ms and a default atMost timeout of 10 seconds.
func AwaitPanic ¶
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 ¶
IsAwaitTimeoutError checks if an error starts with the "TIMEOUT_ERROR" prefix.
Types ¶
This section is empty.