Documentation
¶
Index ¶
- Constants
- type ActionResult
- type CallbackFn
- type Config
- type Manager
- 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.Logger)
- 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 ActionResult ¶ added in v0.3.3
func NewActionResult ¶ added in v0.3.3
func NewActionResult(val any, err error) *ActionResult
func NewEmptyActionResult ¶ added in v0.3.3
func NewEmptyActionResult() *ActionResult
func (*ActionResult) IsError ¶ added in v0.3.3
func (ar *ActionResult) IsError() bool
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.Logger // Logger. }
Process configuration structure.
type Manager ¶
type Manager interface { SetLogger(logger.Logger) Logger() logger.Logger 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 structure.
To use,
1) Create a new process manager:
```go
procmgr := process.NewManager()
```
2) Create your process configuration:
```go
conf := &process.Config{ Name: "Windows 95", Interval: 10, // seconds Function: func(state **State) { // Crash or something. } }
```
3) Create the process itself.
```go
proc := procmgr.Create(conf)
```
4) Run the process.
```go
procmgr.Run("Windows 95")
```
/or/
```go
proc.Run()
```
Manager is optional, as you can create processes directly.
func NewManagerWithContext ¶
Create a new process manager with a given parent 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:
```go
conf := &process.Config{ Name: "Windows 95", Interval: 10, // 10 seconds. Function: func(state **State) { // Crash or something. }, }
```
2) Create a process:
```go
proc := process.NewProcess(conf)
```
3) Run the process:
```go
go proc.Run()
```
4) Send data to the process:
```go
proc.Send("Blue Screen of Death")
```
5) Read data from the process:
```go
data := proc.Receive()
```
6) Stop the process
```go
proc.Stop()
```
will stop the process.
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 ¶
Read data from an external entity with blocking.
func (*State) SendBlocking ¶
Send data from a process to an external entity with blocking.