github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/examples/multiple-runtimes/README.md (about)

     1  ## Multiple runtimes
     2  
     3  Sometimes, a Wasm module might want a stateful host module. In that case, we have to create
     4  multiple `wazero.Runtime` if we want to run it multiple times.
     5  This example shows how to use multiple Runtimes while sharing
     6  the same compilation caches so that we could reduce the compilation time of Wasm modules.
     7  
     8  In this example, we create two `wazero.Runtime` which shares the underlying cache, and
     9  instantiate a Wasm module which requires the stateful "env" module on each runtime.
    10  
    11  ```bash
    12  $ go run counter.go
    13  m1 count=0
    14  m2 count=0
    15  m1 count=1
    16  m2 count=1
    17  ```