Documentation
¶
Index ¶
- Variables
- type Listener
- type ListenerCb
- type State
- func (s *State) AddListener(oneShot bool, waitFor time.Duration, cb ListenerCb, errCb func(error)) uint32
- func (s *State) DeferFunc(state int, waitFor time.Duration, fn func(int) error, errFn func(error))
- func (s *State) GetState() int
- func (s *State) RemoveAllStateListeners()
- func (s *State) RemoveStateListener(id uint32)
- func (s *State) SetState(state int)
Constants ¶
This section is empty.
Variables ¶
var ErrListenerClosed = errors.New("Listener closed")
ErrListenerClosed is called when the listener is closed.
var ErrTimeout = errors.New("Timeout")
ErrTimeout is thrown when a state listener timed out
Functions ¶
This section is empty.
Types ¶
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener is a listener of state changes
type ListenerCb ¶
ListenerCb is a callback that can be attached to a state listener
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is a keeper of state
func (*State) AddListener ¶
func (s *State) AddListener(oneShot bool, waitFor time.Duration, cb ListenerCb, errCb func(error)) uint32
AddListener returns a new state listener. If oneShot means it is executed once and then removed waitFor means it is time constrained. If a timeout occurs, errCb is called with ErrTimeOut and the listener is removed. If waitFor == 0 and oneShot is false, it runs until RemoveListener is called.
func (*State) DeferFunc ¶
DeferFunc defers the execution of a function until the state has changed, or the timeout has occurred. If timeout == 0 then we will wait for ever
func (*State) RemoveAllStateListeners ¶
func (s *State) RemoveAllStateListeners()
RemoveAllStateListeners removes all state listeners. Should be called before the State is deleted
func (*State) RemoveStateListener ¶
RemoveStateListener removes a state listener and closes the channels