Pass context into NewRuntime (#748)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
14
runtime.go
14
runtime.go
@@ -16,7 +16,7 @@ import (
|
||||
// Ex. The below is the basic initialization of wazero's WebAssembly Runtime.
|
||||
//
|
||||
// ctx := context.Background()
|
||||
// r := wazero.NewRuntime()
|
||||
// r := wazero.NewRuntime(ctx)
|
||||
// defer r.Close(ctx) // This closes everything this Runtime created.
|
||||
//
|
||||
// module, _ := r.InstantiateModuleFromBinary(ctx, wasm)
|
||||
@@ -52,7 +52,7 @@ type Runtime interface {
|
||||
//
|
||||
// Ex.
|
||||
// ctx := context.Background()
|
||||
// r := wazero.NewRuntime()
|
||||
// r := wazero.NewRuntime(ctx)
|
||||
// defer r.Close(ctx) // This closes everything this Runtime created.
|
||||
//
|
||||
// module, _ := r.InstantiateModuleFromBinary(ctx, wasm)
|
||||
@@ -107,7 +107,7 @@ type Runtime interface {
|
||||
//
|
||||
// Ex.
|
||||
// ctx := context.Background()
|
||||
// r := wazero.NewRuntime()
|
||||
// r := wazero.NewRuntime(ctx)
|
||||
// defer r.CloseWithExitCode(ctx, 2) // This closes everything this Runtime created.
|
||||
//
|
||||
// // Everything below here can be closed, but will anyway due to above.
|
||||
@@ -120,14 +120,14 @@ type Runtime interface {
|
||||
}
|
||||
|
||||
// NewRuntime returns a runtime with a configuration assigned by NewRuntimeConfig.
|
||||
func NewRuntime() Runtime {
|
||||
return NewRuntimeWithConfig(NewRuntimeConfig())
|
||||
func NewRuntime(ctx context.Context) Runtime {
|
||||
return NewRuntimeWithConfig(ctx, NewRuntimeConfig())
|
||||
}
|
||||
|
||||
// NewRuntimeWithConfig returns a runtime with the given configuration.
|
||||
func NewRuntimeWithConfig(rConfig RuntimeConfig) Runtime {
|
||||
func NewRuntimeWithConfig(ctx context.Context, rConfig RuntimeConfig) Runtime {
|
||||
config := rConfig.(*runtimeConfig)
|
||||
store, ns := wasm.NewStore(config.enabledFeatures, config.newEngine(config.enabledFeatures))
|
||||
store, ns := wasm.NewStore(config.enabledFeatures, config.newEngine(ctx, config.enabledFeatures))
|
||||
return &runtime{
|
||||
store: store,
|
||||
ns: &namespace{store: store, ns: ns},
|
||||
|
||||
Reference in New Issue
Block a user