action

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package action provides the interface and utilities for funnctions which takes a context and returns an error on failure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action = func(context.Context) error

Action is a function that takes a context and returns an error.

func Combine

func Combine(name string, steps ...Action) Action

Combine combines a list of functions from Context to error into one function. Combine adds the name of the operation into the error message to clarify the step. It is recommended to start the name of operations with a verb, e.g.,

"open Downloads and right click a folder"

Then the failure msg would be like:

"failed to open Downloads and right click a folder on step ..."

func IfSuccessThen

func IfSuccessThen(preFunc, action Action) Action

IfSuccessThen returns a function that runs action only if the first function succeeds. The function returns an error only if the preFunc succeeds but action fails, It returns nil in all other situations. Example:

  dialog := nodewith.Name("Dialog").Role(role.Dialog)
  button := nodewith.Name("Ok").Role(role.Button).Ancestor(dialog)
  ui := uiauto.New(tconn)
  if err := action.IfSuccessThen(ui.Withtimeout(5*time.Second).WaitUntilExists(dialog), ui.LeftClick(button))(ctx); err != nil {
	    ...
  }

func Named

func Named(name string, fn Action) Action

Named gives a name to an action. It logs when an action starts, and if the action fails, tells you the name of the failing action.

func Retry

func Retry(n int, action Action, interval time.Duration) Action

Retry returns a function that retries a given action if it returns error. The action will be executed up to n times, including the first attempt. The last error will be returned. Any other errors will be silently logged. Between each run of the loop, it will sleep according the specified interval.

func RetrySilently

func RetrySilently(n int, action Action, interval time.Duration) Action

RetrySilently returns a function that retries a given action if it returns error. The action will be executed up to n times, including the first attempt. The last error will be returned. Any other errors will be ignored. Between each run of the loop, it will sleep according the specified interval.

func Sleep

func Sleep(duration time.Duration) Action

Sleep returns a function that sleeps for the specified duration.

Jump to

Keyboard shortcuts

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