Documentation
¶
Index ¶
- Constants
- type CallbackFn
- type Config
- type IManager
- type Manager
- func (pm *Manager) Add(proc *Process)
- func (pm *Manager) Context() context.Context
- func (pm *Manager) Count() int
- func (pm *Manager) Create(config *Config) *Process
- func (pm *Manager) Find(name string) (*Process, bool)
- func (pm *Manager) Processes() *[]*Process
- func (pm *Manager) Run(name string) bool
- func (pm *Manager) SetContext(parent context.Context)
- func (pm *Manager) SetLogger(lgr logger.ILogger)
- func (pm *Manager) Stop(name string) bool
- func (pm *Manager) StopAll() bool
- type Process
- func (p *Process) Context() context.Context
- func (p *Process) Query(arg interface{}) interface{}
- func (p *Process) Receive() interface{}
- func (p *Process) ReceiveNonBlocking() (interface{}, bool)
- func (p *Process) Run() bool
- func (p *Process) Send(data interface{})
- func (p *Process) SendNonBlocking(data interface{})
- func (p *Process) SetContext(parent context.Context)
- func (p *Process) SetLogger(lgr logger.ILogger)
- func (p *Process) SetWaitGroup(wg *sync.WaitGroup)
- func (p *Process) Stop() bool
- type QueryFn
- type State
Constants ¶
const (
EventLoopSleep time.Duration = 250 * time.Millisecond
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Name string // Pretty name. Interval int // `RunEvery` time interval. Function CallbackFn // `Action` callback. OnStart CallbackFn // `Start` callback. OnStop CallbackFn // `Stop` callback. OnQuery QueryFn // `Query` callback. Logger logger.ILogger // Logger. }
Process configuration structure.
type IManager ¶
type IManager interface { SetLogger(logger.ILogger) SetContext(context.Context) Context() context.Context Create(*Config) *Process Add(*Process) Find(string) (*Process, bool) Run(string) bool Stop(string) bool StopAll() bool Processes() *[]*Process Count() int }
Process manager interface.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Process manager structure.
To use,
1) Create a new process manager:
procmgr := process.NewManager()
2) Create your process configuration:
conf := &process.Config{ Name: "Windows 95", Interval: 10, // seconds Function: func(state **State) { // Crash or something. } }
3) Create the process itself.
proc := procmgr.Create(conf)
4) Run the process.
procmgr.Run("Windows 95")
/or/
proc.Run()
func NewManagerWithContext ¶
Create a new process manager with a given parent context.
func (*Manager) Run ¶
Run the named process.
Returns 'false' if the process is not found; otherwise returns the result of the process execution.
func (*Manager) SetContext ¶
Set the process manager's context.
type Process ¶
type Process struct { sync.Mutex Name string // Pretty name. Function CallbackFn // `Action` callback. OnStart CallbackFn // `Start` callback. OnStop CallbackFn // `Stop` callback. OnQuery QueryFn // `Query` callback. Running bool // Is the process running? Interval time.Duration // `RunEvery` time interval. // contains filtered or unexported fields }
Process structure.
To use:
1) Create a config:
conf := &process.Config{ Name: "Windows 95", Interval: 10, // 10 seconds. Function: func(state **State) { // Crash or something. }, }
2) Create a process:
proc := process.NewProcess(conf)
3) Run the process:
go proc.Run()
4) Send data to the process:
proc.Send("Blue Screen of Death")
5) Read data from the process:
data := proc.Receive()
6) Stop the process
proc.Stop()
func NewProcess ¶
Create a new process with the given configuration.
func NewProcessWithContext ¶
Create a new process with the given configuration and parent context.
func (*Process) Query ¶ added in v0.1.1
func (p *Process) Query(arg interface{}) interface{}
Query the running process.
This allows interaction with the process's base object without using `Action`.
func (*Process) Receive ¶
func (p *Process) Receive() interface{}
Receive data from the process with blocking.
func (*Process) ReceiveNonBlocking ¶
Receive data from the process without blocking.
func (*Process) Run ¶
Run the process with its action taking place on a continuous loop.
Returns 'true' if the process has been started, or 'false' if it is already running.
func (*Process) Send ¶
func (p *Process) Send(data interface{})
Send data to the process with blocking.
func (*Process) SendNonBlocking ¶
func (p *Process) SendNonBlocking(data interface{})
Send data to the process without blocking.
func (*Process) SetContext ¶
Set the process's context.
func (*Process) SetWaitGroup ¶
Set the process's wait group.
type State ¶
type State struct {
// contains filtered or unexported fields
}
Internal state for processes.
func (*State) ReceiveBlocking ¶
func (ps *State) ReceiveBlocking() interface{}
Read data from an external entity with blocking.
func (*State) SendBlocking ¶
func (ps *State) SendBlocking(data interface{})
Send data from a process to an external entity with blocking.