Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultPrinterInspector(node Node, tick Tick) ([]interface{}, interface{})
- type Context
- func (c *Context) Cancel([]Node) (Status, error)
- func (c *Context) Done([]Node) (Status, error)
- func (c *Context) Err([]Node) (Status, error)
- func (c *Context) Init([]Node) (Status, error)
- func (c *Context) Tick(fn func(ctx context.Context, children []Node) (Status, error)) Tick
- func (c *Context) WithCancel(parent context.Context) *Context
- func (c *Context) WithDeadline(parent context.Context, deadline time.Time) *Context
- func (c *Context) WithTimeout(parent context.Context, timeout time.Duration) *Context
- type Frame
- type Manager
- type Node
- type Printer
- type Status
- type Tick
- type Ticker
- type TreePrinter
- type TreePrinterNode
Constants ¶
const ( // Running indicates that the Tick for a given Node is currently running Running // Success indicates that the Tick for a given Node completed successfully Success // Failure indicates that the Tick for a given Node failed to complete successfully Failure )
Variables ¶
var ( // ErrManagerStopped is returned by the manager implementation in this package (see also NewManager) in the case // that Manager.Add is attempted after the manager has already started to stop. Use errors.Is to check this case. ErrManagerStopped error = errManagerStopped{/* contains filtered or unexported fields */} )
Functions ¶
func DefaultPrinterInspector ¶
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) Cancel ¶
Cancel implements a tick that will cancel the receiver's context (noop if it has none) then succeed
func (*Context) Done ¶
Done implements a tick that will block on the receiver's context being canceled (noop if it has none) then succeed
func (*Context) Err ¶
Err implements a tick that will succeed if the receiver does not have a context or it has been canceled
func (*Context) Init ¶
Init implements a tick that will cancel existing context, (re)initialise the context, then succeed, note that it must not be called concurrently with any other method, and it must be ticked prior to any Context.Tick tick
func (*Context) Tick ¶
Tick returns a tick that will call fn with the receiver's context, returning nil if fn is nil (for consistency with other implementations in this package), note that a Init node must have already been ticked on all possible execution paths, or a panic may occur, due to fn being passed a nil context.Context
func (*Context) WithDeadline ¶
type Manager ¶
func NewManager ¶
func NewManager() Manager
type Node ¶
Node represents an node in a tree, that can be ticked
type Printer ¶
var ( DefaultPrinter Printer = TreePrinter{ Inspector: DefaultPrinterInspector, Formatter: DefaultPrinterFormatter, } )
type Status ¶
type Status int
Status is a type with three valid values, Running, Success, and Failure, the three possible states for BTs
type Tick ¶
Tick represents the logic for a node, which may or may not be stateful
func Any ¶
Any wraps a tick such that non-error non-running statuses will be overridden with a success if at least one child succeeded - which is achieved by encapsulation of children, before passing them into the wrapped tick. Nil will be returned if tick is nil, and nil children will be passed through as such.
func Background ¶
type TreePrinter ¶
type TreePrinter struct { Inspector func(node Node, tick Tick) (meta []interface{}, value interface{}) Formatter func() TreePrinterNode }
type TreePrinterNode ¶
type TreePrinterNode interface { Add(meta []interface{}, value interface{}) TreePrinterNode Bytes() []byte }
func DefaultPrinterFormatter ¶
func DefaultPrinterFormatter() TreePrinterNode
DefaultPrinterFormatter is used by DefaultPrinter