Documentation
¶
Index ¶
- Constants
- Variables
- func SetProcessManager(ctx context.Context, inst Manager) (context.Context, error)
- type CallbackFn
- type Config
- type Manager
- type Process
- func (p *Process) Context() context.Context
- func (p *Process) Invoke(event events.Event) events.Event
- func (p *Process) Name() string
- func (p *Process) Query(arg interface{}) interface{}
- func (p *Process) RespondsTo(event events.Event) bool
- func (p *Process) Run() bool
- func (p *Process) Running() bool
- func (p *Process) Stop() bool
- func (p *Process) Type() string
- type QueryFn
- type State
- type StopAllResults
Constants ¶
const (
ContextKeyProcManager = "_DI_PROC_MGR"
)
Variables ¶
var (
ErrValueNotProcessManager = errors.Base("value is not process.Manager")
)
Functions ¶
Types ¶
type Config ¶
type Config struct {
Name string // Pretty name.
Interval types.Duration // `RunEvery` time interval.
Function CallbackFn // `Action` callback.
OnStart CallbackFn // `Start` callback.
OnStop CallbackFn // `Stop` callback.
OnQuery QueryFn // `Query` callback.
Responder responder.Respondable // Responder object.
}
Process configuration structure.
type Manager ¶
type Manager interface {
Logger() logger.Logger
SetContext(context.Context)
SetLogger(logger.Logger)
Context() context.Context
Create(*Config) *Process
Add(*Process)
Find(string) (*Process, bool)
Run(string) bool
Stop(string) bool
StopAll() StopAllResults
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 GetProcessManager ¶ added in v1.0.5
Get the process manager from the given context.
Will return `ErrValueNotProcessManager` if the value in the context is not of type `process.Manager`.
func MustGetProcessManager ¶ added in v1.0.5
Attempt to get the process manager from the given context. Panics if the operation fails.
func NewManagerWithContext ¶
Create a new process manager with a given parent context.
type Process ¶
type Process struct {
// 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) 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.
type State ¶
type State struct {
// contains filtered or unexported fields
}
Internal state for processes.