Skip to content

Commit

Permalink
doc: adds comments on anonymous module names (#2275)
Browse files Browse the repository at this point in the history
Anonymous modules are introduced like a few years ago
to allow multiple/concurrent instantiations from a single
binary. That was not documented enough well, so this
adds doc comments in the API.

Signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake committed Jun 28, 2024
1 parent 77222b7 commit 26d3aeb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,20 @@ type ModuleConfig interface {
WithFSConfig(FSConfig) ModuleConfig

// WithName configures the module name. Defaults to what was decoded from
// the name section. Empty string ("") clears any name.
// the name section. Duplicate names are not allowed in a single Runtime.
//
// Calling this with the empty string "" makes the module anonymous.
// That is useful when you want to instantiate the same CompiledModule multiple times like below:
//
// for i := 0; i < N; i++ {
// // Instantiate a new Wasm module from the already compiled `compiledWasm` anonymously without a name.
// instance, err := r.InstantiateModule(ctx, compiledWasm, wazero.NewModuleConfig().WithName(""))
// // ....
// }
//
// See the `concurrent-instantiation` example for a complete usage.
//
// Non-empty named modules are available for other modules to import by name.
WithName(string) ModuleConfig

// WithStartFunctions configures the functions to call after the module is
Expand Down

0 comments on commit 26d3aeb

Please sign in to comment.