process

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ContextKeyProcManager = "_DI_PROC_MGR"
)

Variables

View Source
var (
	ErrValueNotProcessManager = errors.Base("value is not process.Manager")
)

Functions

func SetProcessManager added in v1.0.5

func SetProcessManager(ctx context.Context, inst Manager) (context.Context, error)

Set the process manager value to the context map.

Types

type CallbackFn

type CallbackFn func(*State)

Callback function.

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.

func NewConfig added in v1.0.5

func NewConfig() *Config

Create a default process configuration.

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

func GetProcessManager(ctx context.Context) (Manager, error)

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

func MustGetProcessManager(ctx context.Context) Manager

Attempt to get the process manager from the given context. Panics if the operation fails.

func NewManager

func NewManager() Manager

Create a new process manager.

func NewManagerWithContext

func NewManagerWithContext(parent context.Context) Manager

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

func NewProcess(config *Config) *Process

Create a new process with the given configuration.

func NewProcessWithContext

func NewProcessWithContext(parent context.Context, config *Config) *Process

Create a new process with the given configuration and parent context.

func (*Process) Context added in v0.1.1

func (p *Process) Context() context.Context

Return the context for the process.

func (*Process) Invoke added in v1.0.5

func (p *Process) Invoke(event events.Event) events.Event

func (*Process) Name

func (p *Process) Name() string

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) RespondsTo added in v1.0.5

func (p *Process) RespondsTo(event events.Event) bool

func (*Process) Run

func (p *Process) Run() bool

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

func (p *Process) Running() bool

Is the process running?

func (*Process) Stop

func (p *Process) Stop() bool

Stop the process.

Returns 'true' if the process was successfully stopped, or 'false' if it was not running.

func (*Process) Type added in v1.0.5

func (p *Process) Type() string

type QueryFn added in v0.1.1

type QueryFn func(interface{}) interface{}

type State

type State struct {
	// contains filtered or unexported fields
}

Internal state for processes.

func (*State) Context added in v0.1.1

func (ps *State) Context() context.Context

Return the context for the parent process.

func (*State) Invoke added in v1.0.5

func (ps *State) Invoke(event events.Event) (events.Event, bool)

func (*State) Logger

func (ps *State) Logger() logger.Logger

func (*State) RespondsTo added in v1.0.5

func (ps *State) RespondsTo(event events.Event) bool

type StopAllResults added in v1.0.5

type StopAllResults map[string]bool

Jump to

Keyboard shortcuts

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