utils

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2017 License: MIT Imports: 8 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectWithRetry

func ConnectWithRetry(url string, delay int) (socket *websocket.Conn, err error)

ConnectWithRetry will attempt to connect a websocket to the given url retrying if needed with the given delay (milliseconds) between calls

func ListenForMessages

func ListenForMessages(socket *websocket.Conn, onMessage func(structs.Message) error, onError func(error))

ListenForMessages continuously reads from the given websocket calling the given function on each received message

func MessageFromJSON

func MessageFromJSON(bytes []byte) (structs.Message, error)

MessageFromJSON unmarshals bytes into a message

func Retry

func Retry(delayInMilliseconds int, attemptFn func() bool)

Retry will execute the given function until it returns true with the given delay (milliseconds) between calls

func WaitFor

func WaitFor(condition func() bool, errorMessage string) error

WaitFor waits a maximum of 10 seconds the given condition to become true returning an error with the given message if and only if it does not

func WaitForMessageWithName

func WaitForMessageWithName(obj ObjectWithMessages, name string) (structs.Message, error)

WaitForMessageWithName waits to receive a message with the given name

func WaitForf

func WaitForf(condition func() bool, errorFn func() error) error

WaitForf is similar to WaitFor but accepts a func to generate the error message

Types

type ObjectWithMessages

type ObjectWithMessages interface {
	GetReceivedMessages() []structs.Message
}

ObjectWithMessages is the interface for a object passed into WaitForMessageWithName

Jump to

Keyboard shortcuts

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