# `Alternera.PluginWasmFramework.Modules`
[🔗](https://github.com/10e-ab/alternera-wasm/blob/v0.9.0/alternera_plugin_wasm_framework/lib/alternera/plugin_wasm_framework/modules.ex#L1)

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.

# `t`

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

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

# `digest`

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

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

# `load`

```elixir
@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`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
