Documentation
¶
Index ¶
- Constants
- Variables
- func Run(ctx context.Context, fn func(*sobek.Runtime) error) error
- func RunModule(ctx context.Context, module sobek.CyclicModuleRecord, args ...any) (sobek.Value, error)
- func RunProgram(ctx context.Context, program *sobek.Program) (sobek.Value, error)
- func RunString(ctx context.Context, str string) (sobek.Value, error)
- func SetScheduler(s Scheduler)
- func WithValue(ctx context.Context, key, value any) context.Context
- type Context
- type Metrics
- type Scheduler
- type SchedulerOptions
Constants ¶
View Source
const ( // DefaultTimeoutGetVM default get js.VM timeout DefaultTimeoutGetVM = 500 * time.Millisecond // DefaultMaxRetriesGetVM default retries times DefaultMaxRetriesGetVM = 3 )
Variables ¶
View Source
var ( // ErrSchedulerClosed the scheduler was closed error ErrSchedulerClosed = errors.New("scheduler was closed") )
Functions ¶
func Run ¶
Run executes the given function
example:
err := ski.Run(context.Background(), func(rt *sobek.Runtime) error {
_, err := rt.RunString(`console.log('hello world')`)
return err
})
if err != nil {
panic(err)
}
func RunModule ¶
func RunModule(ctx context.Context, module sobek.CyclicModuleRecord, args ...any) (sobek.Value, error)
RunModule the sobek.CyclicModuleRecord
example:
module, err := js.CompileModule("add", "export default (a, b) => a + b")
if err != nil {
panic(err)
}
value, err := ski.RunModule(context.Background(), module, 1, 2)
if err != nil {
panic(err)
}
fmt.Println(value.Export()) // 3
func RunProgram ¶
RunProgram executes the given sobek.Program
example:
program, err := sobek.Compile("", `1 + 1`, false)
if err != nil {
panic(err)
}
value, err := ski.RunProgram(context.Background(), program)
if err != nil {
panic(err)
}
fmt.Println(value.Export()) // 2
Types ¶
type Context ¶
type Context interface {
context.Context
// SetValue store key with value
SetValue(key, value any)
}
Context multiple values context
type Metrics ¶
type Metrics struct {
Max int `json:"max"` // max vm size
Idle int `json:"idle"` // idle vm size
Remaining int `json:"remaining"` // remaining creatable vm size
}
Metrics contains Scheduler metrics
type Scheduler ¶
type Scheduler interface {
// Shrink the idle VM to initial VM size
Shrink()
// Metrics Scheduler metrics
Metrics() Metrics
// Close the scheduler
Close() error
// contains filtered or unexported methods
}
Scheduler the js.VM scheduler
func NewScheduler ¶
func NewScheduler(opt SchedulerOptions) Scheduler
NewScheduler create a new Scheduler
type SchedulerOptions ¶
type SchedulerOptions struct {
InitialVMs uint `yaml:"initial-vms" json:"initialVMs"`
MaxVMs uint `yaml:"max-vms" json:"maxVMs"`
GetMaxRetries uint `yaml:"get-max-retries" json:"maxRetries"`
GetTimeout time.Duration `yaml:"get-timeout" json:"timeout"`
VMOptions []js.Option `yaml:"-"` // options for NewVM
}
SchedulerOptions options
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
echarts
command
|
|
|
react
command
|
|
|
vue
command
|
|
|
Package js the JavaScript implementation.
|
Package js the JavaScript implementation. |
|
modulestest
Package modulestest the module test vm
|
Package modulestest the module test vm |
|
cache
Package cache the cache JS implementation
|
Package cache the cache JS implementation |
|
crypto
Package crypto the crypto JS implementation
|
Package crypto the crypto JS implementation |
Click to show internal directories.
Click to hide internal directories.