ipc

package
v0.0.0-...-8aeb8a1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JitsuScriptResultCommand = "_JITSU_RESULT"
)

Variables

View Source
var ErrOutOfMemory = errors.New("out of memory")

Functions

This section is empty.

Types

type CommandResponse

type CommandResponse struct {
	Command string      `json:"command"`
	Payload interface{} `json:"payload"`
}

type DataListener

type DataListener interface {

	// Data is called for each line of output.
	Data(data []byte)
}

DataListener is used to listen for multiline execution output.

type Governor

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

Governor is responsible for keeping the Process alive. It will restart the process if it dies.

func Govern

func Govern(process Process, standalone bool) (*Governor, error)

Govern starts the process and passes it to Governor instance.

func (*Governor) Close

func (g *Governor) Close() error

func (*Governor) Exchange

func (g *Governor) Exchange(ctx context.Context, data []byte, listener DataListener) ([]byte, error)

Exchange sends request data and returns response data.

func (*Governor) ExchangeDirect

func (g *Governor) ExchangeDirect(ctx context.Context, data []byte, listener DataListener) ([]byte, error)

func (*Governor) String

func (g *Governor) String() string

type Interface

type Interface interface {

	// Send sends a message to the process.
	Send(ctx context.Context, data []byte) error

	// Receive receives a message from the process.
	// It is advisable to support context.Context.Done() in method implementations
	// so as not to infinitely block.
	Receive(ctx context.Context, listener DataListener) ([]byte, error)
}

Interface describes generic IPC interface.

type Mutex

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

Mutex provides an interruptible mutex implementation.

func (*Mutex) Lock

func (mu *Mutex) Lock(ctx context.Context) (unlock func(), err error)

Lock attempts to lock the mutex in the given context.Context.

type Process

type Process interface {
	Interface

	// String should return a human-readable process description.
	String() string

	// Spawn spawns a new process copy and returns it.
	Spawn() (Process, error)

	// Kill kills the current running process.
	Kill()

	// Wait waits for the current process to exit. Returns stderr output if present
	Wait() (string, error)
}

Process describes a process with no acquired state (except for the initial state acquired on start) which can be restarted (respawned) with no data or other loss. Process instance should not be started manually – instead, it should contain all that is necessary to start the process and be supplied to Govern function.

type StdIO

type StdIO struct {
	Dir  string
	Path string
	Args []string
	Env  []string

	CommandProcessor func(commandName string, payload []byte) (*CommandResponse, error)
	// contains filtered or unexported fields
}

StdIO allows to start to process and communicate to it via standard input/output. Note that it currently uses '\n' for delimiting sent messages.

func (*StdIO) Kill

func (p *StdIO) Kill()

func (*StdIO) Receive

func (p *StdIO) Receive(ctx context.Context, listener DataListener) ([]byte, error)

func (*StdIO) Send

func (p *StdIO) Send(_ context.Context, data []byte) error

func (*StdIO) Spawn

func (p *StdIO) Spawn() (Process, error)

func (*StdIO) String

func (p *StdIO) String() string

func (*StdIO) Wait

func (p *StdIO) Wait() (string, error)

Jump to

Keyboard shortcuts

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