Alternera.PluginWasmFramework.Modules (alternera_plugin_wasm_framework v0.9.0)

Copy Markdown View Source

The node's compiled language modules, one per module digest (SHA-256 of the .wasm bytes), kept in :persistent_term: compiling an interpreter takes 150 to 500 ms, so it happens once per node, when the language plugin's package starts (load/2 from its application's start/2), not on the first request. A call finds its module by digest (fetch/1); a module not loaded yet is compiled then, once.

A digest's entry is never replaced: a new build of a language is a new file with a new digest. load/2 also remembers the entry by path, so a step's call does not read and hash the file each time; a file replaced in place is picked up when the node restarts. Two processes that miss at the same moment compile once: the second waits for the first's entry.

Summary

Types

t()

A loaded module: its digest and what the runtime prepared.

Functions

The digest of wasm, lower-case hex SHA-256.

Compiles the module at path (once per node) and answers its entry. Logs and answers the error when the file cannot be read or compiled.

Compiles wasm (once per node per digest) and answers its entry.

Types

t()

@type t() :: %{digest: String.t(), runtime: module(), prepared: term()}

A loaded module: its digest and what the runtime prepared.

Functions

digest(wasm)

@spec digest(binary()) :: String.t()

The digest of wasm, lower-case hex SHA-256.

load(path, runtime \\ Runtime.impl())

@spec load(Path.t(), module()) :: {:ok, t()} | {:error, String.t()}

Compiles the module at path (once per node) and answers its entry. Logs and answers the error when the file cannot be read or compiled.

prepare(wasm, runtime \\ Runtime.impl())

@spec prepare(binary(), module()) :: {:ok, t()} | {:error, String.t()}

Compiles wasm (once per node per digest) and answers its entry.