Documentation ¶
Index ¶
- Variables
- type Factory
- type IpcFunc
- type Pool
- type Process
- func (p *Process) Alive() <-chan struct{}
- func (p *Process) Checkpoint(timeout time.Duration) error
- func (p *Process) Close() error
- func (p *Process) Console() []byte
- func (p *Process) Eval(ctx context.Context, code string, opts map[string]any) (any, error)
- func (p *Process) EvalChannel(code string, opts map[string]any) (chan map[string]any, error)
- func (p *Process) GetVersion(what string) string
- func (p *Process) Kill()
- func (p *Process) Log(msg string, args ...any)
- func (p *Process) MakeResponse() (string, chan map[string]any)
- func (p *Process) Run(code string, opts map[string]any)
- func (p *Process) Set(v string, val any)
- func (p *Process) SetContext(ctx context.Context)
- func (p *Process) SetIPC(name string, f IpcFunc)
Constants ¶
This section is empty.
Variables ¶
var ( ErrTimeout = errors.New("nodejs: timeout reached") ErrDeadProcess = errors.New("nodejs: process has died") )
Functions ¶
This section is empty.
Types ¶
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
type Pool ¶
type Pool struct { Timeout time.Duration // timeout for running nodejs, defaults to 10 second if zero // contains filtered or unexported fields }
func (*Pool) Take ¶
Take returns a Process from the pool and will wait until one is available, unless the context is cancelled.
func (*Pool) TakeIfAvailable ¶
TakeIfAvailable returns a Process if any is available, or nil if not
type Process ¶
func (*Process) Alive ¶
func (p *Process) Alive() <-chan struct{}
Alive returns a channel that will be closed when the nodejs process ends
func (*Process) Checkpoint ¶
Checkpoint ensures the process is running and returns within the specified time
func (*Process) Close ¶
Close closes the nodejs stdin pipe, causing the process to die of natual causes
func (*Process) Eval ¶
Eval is similar to Run, but will return whatever the javascript code evaluated returned
func (*Process) EvalChannel ¶ added in v0.1.2
EvalChannel will execute the provided code and return a channel that can be used to read the response once it is made available
func (*Process) GetVersion ¶
func (*Process) Log ¶
Log appends a message to the nodejs console directly so it can be retrieved with Console()
func (*Process) MakeResponse ¶
MakeResponse returns a handler id and a channel that will see data appended to it if triggered from the javascript side with a response event to that id. This can be useful for asynchronisous events.
func (*Process) Run ¶
Run executes the provided code in the nodejs instance. options can contain things like filename. If filename ends in .mjs, the code will be run as a JS module