state

package
v0.0.0-...-7a34736 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrListenerClosed = errors.New("Listener closed")

ErrListenerClosed is called when the listener is closed.

View Source
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

type ListenerCb func(state int) error

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 NewState

func NewState(initialState int) *State

NewState creates a new state and initialize it with an initial 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

func (s *State) DeferFunc(state int, waitFor time.Duration, fn func(int) error, errFn func(error))

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) GetState

func (s *State) GetState() int

GetState returns the current state of the GetState

func (*State) RemoveAllStateListeners

func (s *State) RemoveAllStateListeners()

RemoveAllStateListeners removes all state listeners. Should be called before the State is deleted

func (*State) RemoveStateListener

func (s *State) RemoveStateListener(id uint32)

RemoveStateListener removes a state listener and closes the channels

func (*State) SetState

func (s *State) SetState(state int)

SetState sets the state

Jump to

Keyboard shortcuts

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