-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.go
More file actions
36 lines (31 loc) · 899 Bytes
/
runtime.go
File metadata and controls
36 lines (31 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package runtimes
import (
"context"
"time"
)
// EmbeddedRuntime represents an embeddable script engine (goja, quickjs, yaegi).
type EmbeddedRuntime interface {
Name() string
NewVM(opts VMOptions) (VM, error)
}
// VM represents a single execution instance of an embedded runtime.
type VM interface {
InjectBridge(bridge map[string]any) error
InjectParams(params map[string]any) error
Execute(code string, filename string) (any, error)
Interrupt(reason string)
Close()
}
// VMOptions configures a new VM instance.
type VMOptions struct {
Timeout time.Duration
MaxMemoryMB int
HardMaxMemMB int
}
// ExternalRuntime represents a child-process script engine (Node.js, Python).
type ExternalRuntime interface {
Name() string
Execute(ctx context.Context, script string, function string, params map[string]any, bridge map[string]any) (any, error)
Validate() error
Close() error
}