orbit

package module
v0.0.0-...-812e132 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2019 License: Apache-2.0 Imports: 7 Imported by: 83

README

orbit

A Node.js lambda environment library for Go (Golang).

Features
  • Pre-load npm modules directly
  • Pre-load npm modules from files
  • Pre-load npm modules from folders
  • Interrupt long-running code
  • Configurable stack trace depth limit
  • setTimeout, setInterval, setImmediate built-in
  • Callback for finding npm modules not just on filesystem
  • Easily configure runtime before/after npm modules are loaded
  • Track time spent running code in Node.js environment
Installation
go get github.com/abcum/orbit

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(name string, item interface{})

Add adds a module to the runtime

func OnExit

func OnExit(call func(*Orbit))

OnExit registers a callback for when the program shuts down

func OnFail

func OnFail(call func(*Orbit, error))

OnFail registers a callback for when the program encounters an error

func OnFile

func OnFile(call func(*Orbit, []string) (interface{}, string, error))

OnFile registers a callback for finding required files

func OnInit

func OnInit(call func(*Orbit))

OnInit registers a callback for when the program starts up

Types

type Orbit

type Orbit struct {
	// Underlying Otto instance.
	*otto.Otto
	// Emitter
	*emitr.Emitter
	// contains filtered or unexported fields
}

Orbit is a node.go context.

func New

func New(timeout time.Duration) *Orbit

New creates a new Orbit runtime

func (*Orbit) Context

func (orb *Orbit) Context() context.Context

func (*Orbit) Def

func (orb *Orbit) Def(name string, item interface{})

Def sets a global variable in the runtime

func (*Orbit) Exec

func (orb *Orbit) Exec(name string, code interface{}) (err error)

Exec executes some code. Code may be a string or a byte slice.

func (*Orbit) File

func (orb *Orbit) File(name string, extn string) (code interface{}, file string, err error)

File finds a file relative to the current javascript context.

func (*Orbit) Next

func (orb *Orbit) Next(t Task)

Next signals to the run loop that an asynchronous task is ready to be run.

func (*Orbit) Pull

func (orb *Orbit) Pull(t Task)

Pull removes an asynchronous task from the queue, cleaning up any context data. If all asynchronous events are completed, the script will finish.

func (*Orbit) Push

func (orb *Orbit) Push(t Task)

Push pushes an asynchronous task onto the queue, ensuring that the script does not finish before the task is complete.

func (*Orbit) Quit

func (orb *Orbit) Quit(err error)

Quit exits the current javascript context cleanly, or with an error.

func (*Orbit) WithContext

func (orb *Orbit) WithContext(ctx context.Context) *Orbit

type Task

type Task interface {
	// Startup is called when the task is pushed onto the queue.
	Startup(*Orbit)
	// Cleanup is called when the task is pulled from the queue.
	Cleanup(*Orbit)
	// Execute is called when the task is being called from the run loop.
	Execute(*Orbit) error
}

Task is a job that can be added to the asynchronous queue.

Jump to

Keyboard shortcuts

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