Documentation ¶
Index ¶
- type Callbacks
- func (c *Callbacks) AddContinuous(key Key, callback interface{}) (Tag, error)
- func (c *Callbacks) AddSingleShot(key Key, callback interface{}) (Tag, error)
- func (c *Callbacks) Callback(key Key, tag Tag) (interface{}, error)
- func (c *Callbacks) CallbacksForKey(key Key) ([]interface{}, error)
- func (c *Callbacks) Remove(key Key, tag Tag) error
- type Key
- type KeyFunc
- type Tag
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
KeyFunc is the prototype for functions that should run when the first callback for a key is added and the last one is removed.