Documentation
¶
Overview ¶
Package function_run runs PureFunctions in the QuickJS-NG WASI reactor under wazero.
Index ¶
Constants ¶
const InputPlaceholder = "__PURE_FUNCTION_INPUT__"
InputPlaceholder is the token in Harness that a runner replaces with the input in protobuf JSON form.
Variables ¶
var ErrInstructionBudget = errors.New("the function ran past its instruction budget")
ErrInstructionBudget is returned when a run passes its interrupt checks.
var ErrMemoryBudget = errors.New("the function ran past its memory budget")
ErrMemoryBudget is returned when a run passes its memory limit.
var Harness string
Harness is the module that runs a PureFunction. The browser runner evaluates the same text.
Functions ¶
This section is empty.
Types ¶
type FunctionError ¶
type FunctionError struct {
// Message is the error's string form.
Message string
}
FunctionError is an error the function threw or returned.
func (*FunctionError) Error ¶
func (e *FunctionError) Error() string
Error returns the error message.
type JSONMarshaler ¶
JSONMarshaler is a message with a protobuf JSON form, such as a generated protobuf message.
type JSONUnmarshaler ¶
JSONUnmarshaler decodes a message from its protobuf JSON form.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner runs PureFunctions, each in a fresh QuickJS instance, so one run cannot change the next and every run spends its budget from the start.
func NewRunner ¶
func NewRunner(le *logrus.Entry, compiled wazero.CompilationCache, bytecode *bldr_util_qjsbytecode.Cache) *Runner
NewRunner returns a runner. compiled is shared with other users of the reactor, and nil keeps a cache of its own; bytecode caches function modules and nil compiles them every run.
func (*Runner) Run ¶
func (r *Runner) Run(ctx context.Context, fn *s4wave_function.PureFunction, in JSONMarshaler, out JSONUnmarshaler) error
Run runs fn on in and stores its result in out.
func (*Runner) RunJSON ¶
func (r *Runner) RunJSON(ctx context.Context, fn *s4wave_function.PureFunction, input []byte) ([]byte, error)
RunJSON runs fn on the protobuf JSON input and returns its output as JSON.