nodejs

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 19 Imported by: 0

README

GoDoc

nodejs tools for Go

This contains a few nice tools for using nodejs in go

Usage

First you need a nodejs factory:

factory, err := nodejs.New()
if err != nil {
    // handle error: nodejs could not be found or didn't run
}

You can then start processes directly with factory.New() or use factory.NewPool(0, 0) to get a pool of pre-initialized nodejs instances.

Documentation

Index

Constants

View Source
const CREATE_NO_WINDOW = 0x08000000

Variables

View Source
var (
	ErrTimeout = errors.New("nodejs: timeout reached")
)

Functions

This section is empty.

Types

type Factory

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

func New

func New() (*Factory, error)

func (*Factory) New

func (factory *Factory) New() (*Process, error)

func (*Factory) NewPool

func (f *Factory) NewPool(queueSize, maxProcs int) *Pool

NewPool returns a pool of nodejs processes generated by the factory. The pool will always generate at least queueSize processes in memory and will start new ones as they are taken. Passing queueSize <=0 will use the number of CPUs.

type IpcFunc

type IpcFunc func(map[string]any) (any, error)

type Message

type Message struct {
	Action string           `json:"action"`
	Data   pjson.RawMessage `json:"data"`
	Id     int64            `json:"id"`
}

type Pool

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

func (*Pool) Take

func (pool *Pool) Take(ctx context.Context) (*Process, error)

Take returns a Process from the pool and will wait until one is available, unless the context is cancelled.

func (*Pool) TakeIfAvailable

func (pool *Pool) TakeIfAvailable() *Process

TakeIfAvailable returns a Process if any is available, or nil if not

func (*Pool) TakeTimeout

func (pool *Pool) TakeTimeout(t time.Duration) (*Process, error)

TakeTimeout will return a Process taken from the pool if any is available before the timeout expires.

type Process

type Process struct {
	*exec.Cmd
	// contains filtered or unexported fields
}

func (*Process) Alive

func (p *Process) Alive() <-chan struct{}

func (*Process) Checkpoint

func (p *Process) Checkpoint(timeout time.Duration) error

func (*Process) Close

func (p *Process) Close() error

func (*Process) Console

func (p *Process) Console() []byte

func (*Process) Eval

func (p *Process) Eval(code string, opts map[string]interface{}) (interface{}, error)

func (*Process) GetVersion

func (p *Process) GetVersion(what string) string

func (*Process) Kill

func (p *Process) Kill()

func (*Process) Log

func (p *Process) Log(msg string, args ...interface{})

func (*Process) MakeResponse

func (p *Process) MakeResponse() (string, chan map[string]interface{})

func (*Process) Run

func (p *Process) Run(code string, opts map[string]interface{})

func (*Process) Set

func (p *Process) Set(v string, val interface{})

func (*Process) SetContext

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

func (*Process) SetIPC

func (p *Process) SetIPC(name string, f IpcFunc)

Jump to

Keyboard shortcuts

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