wasm

package
v1.46.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package wasm provides a Wasm runtime for plugins.

Index

Constants

This section is empty.

Variables

View Source
var UnimplementedRuntime = unimplementedRuntime{}

UnimplementedRuntime is an unimplemented Runtime.

Functions

This section is empty.

Types

type CompiledModule

type CompiledModule interface {
	pluginrpc.Runner
	// Close releases all resources held by the compiled module.
	Close(ctx context.Context) error
}

CompiledModule is a Wasm module ready to be run.

It is safe to use this module concurrently. When done, call Close to free resources held by the CompiledModule. All CompiledModules created by the same Runtime will be invalidated when the Runtime is closed.

Memory is limited by the Runtime. To restrict CPU usage, cancel the context.

type Runtime

type Runtime interface {
	// Compile compiles the given Wasm module bytes into a CompiledModule.
	Compile(ctx context.Context, moduleName string, moduleWasm []byte) (CompiledModule, error)
	// Close releases all resources held by the Runtime.
	Close(ctx context.Context) error
}

Runtime is a Wasm runtime.

It is safe to use the Runtime concurrently. Close must be called when done with the Runtime to free resources. All CompiledModules created by the same Runtime will be invalidated when the Runtime is closed.

func NewRuntime

func NewRuntime(ctx context.Context, options ...RuntimeOption) (Runtime, error)

NewRuntime creates a new Wasm Runtime.

type RuntimeOption

type RuntimeOption func(*runtimeOptions)

RuntimeOption is an option for Runtime.

func WithLocalCacheDir

func WithLocalCacheDir(cacheDir string) RuntimeOption

WithLocalCacheDir sets the local cache directory.

The cache directory is used to store compiled Wasm modules. This can be used to speed up subsequent runs of the same module. The internal cache structure and versioning is handled by the Runtime.

This option is only safe use in CLI environments.

func WithMaxMemoryBytes

func WithMaxMemoryBytes(maxMemoryBytes uint32) RuntimeOption

WithMaxMemoryBytes sets the maximum memory size in bytes.

The maximuim memory size is limited to 4 GiB. The default is 512 MiB. Sizes less then the page size (64 KiB) are truncated.

Jump to

Keyboard shortcuts

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