Refactors API to ensure context propagation (#482)
This is an API breaking change that does a few things:
* Stop encouraging practice that can break context propagation:
* Stops caching `context.Context` in `wazero.RuntimeConfig`
* Stops caching `context.Context` in `api.Module`
* Fixes context propagation in function calls:
* Changes `api.Function`'s arg0 from `api.Module` to `context.Context`
* Adds `context.Context` parameter in instantiation (propagates to
.start)
* Allows context propagation for heavy operations like compile:
* Adds `context.Context` as the initial parameter of `CompileModule`
The design we had earlier was a good start, but this is the only way to
ensure coherence when users start correlating or tracing. While adding a
`context.Context` parameter may seem difficult, wazero is a low-level
library and WebAssembly is notoriously difficult to troubleshoot. In
other words, it will be easier to explain to users to pass (even nil) as
the context parameter vs try to figure out things without coherent
context.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package wazero
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"math"
|
||||
"testing"
|
||||
@@ -17,24 +16,6 @@ func TestRuntimeConfig(t *testing.T) {
|
||||
with func(*RuntimeConfig) *RuntimeConfig
|
||||
expected *RuntimeConfig
|
||||
}{
|
||||
{
|
||||
name: "WithContext",
|
||||
with: func(c *RuntimeConfig) *RuntimeConfig {
|
||||
return c.WithContext(context.TODO())
|
||||
},
|
||||
expected: &RuntimeConfig{
|
||||
ctx: context.TODO(),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "WithContext - nil",
|
||||
with: func(c *RuntimeConfig) *RuntimeConfig {
|
||||
return c.WithContext(nil) //nolint
|
||||
},
|
||||
expected: &RuntimeConfig{
|
||||
ctx: context.Background(),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "WithMemoryMaxPages",
|
||||
with: func(c *RuntimeConfig) *RuntimeConfig {
|
||||
|
||||
Reference in New Issue
Block a user