callbacks

package
v0.0.0-...-3e1ade8 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callbacks

type Callbacks struct {
	// contains filtered or unexported fields
}

Callbacks holds a map of callbacks (continuous or single-shot).

func New

func New(name string, firstFunc KeyFunc, lastFunc KeyFunc) *Callbacks

New returns a new Callbacks instance with the given name, firstFunc and lastFunc. The firstFunc function is run before the first callback is added to the map and the lastFunc is run after the last one is removed. Either might be nil which means do not run.

func (*Callbacks) AddContinuous

func (c *Callbacks) AddContinuous(key Key, callback interface{}) (Tag, error)

AddContinous adds a new callback that will fire continuously. When needed it has to be explicitly removed. Returns an associated Tag and nil error on success and Tag(0) and a non-nil error on failure.

func (*Callbacks) AddSingleShot

func (c *Callbacks) AddSingleShot(key Key, callback interface{}) (Tag, error)

AddSingleShot adds a new callback that will only fire once. The callback will be automatically removed from the map when Callback() returns it. Returns a nil error on success and a non-nil error on failure.

func (*Callbacks) Callback

func (c *Callbacks) Callback(key Key, tag Tag) (interface{}, error)

Callback returns the callback associated with Key and Tag. If the callback is one-shot, it will also automatically remove it. Returns the callback (as an interface{}) and a nil error on success and nil and a non-nil error on failure.

func (*Callbacks) CallbacksForKey

func (c *Callbacks) CallbacksForKey(key Key) ([]interface{}, error)

CallbacksForKey returns all callbacks associated with the given key. Returns a slice of callbacks (as interfaces{}) and a nil error on success and nil and a non-nil error on failure.

func (*Callbacks) Remove

func (c *Callbacks) Remove(key Key, tag Tag) error

Remove removes a callback that matches the given key or tag. Returns a nil error on success and a non-nil error in failure. Returns a nil error on success and a non-nil error on failure.

type Key

type Key uint64

Key represents a primary key for the callback map. It will usually be either an unity.EventType or a dji.Key.

type KeyFunc

type KeyFunc func(key Key) error

KeyFunc is the prototype for functions that should run when the first callback for a key is added and the last one is removed.

type Tag

type Tag uint64

Tag represents a secondary key for the callback map. It is used to track callbacks so we are able to remove a continuous callback (or, internally, to auto-remove a single-shot callback).

Jump to

Keyboard shortcuts

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