Skip to content

Commit

Permalink
Add indirection to system module, so that we can hook in event bus.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed Aug 14, 2024
1 parent d85f3e7 commit 3a0ee62
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion system/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ type HostConfig struct {
}

func (c HostConfig) Instantiate(ctx context.Context, r wazero.Runtime) (api.Module, error) {
return r.NewHostModuleBuilder("ww").
mod, err := r.NewHostModuleBuilder("ww").
NewFunctionBuilder().
WithGoModuleFunction(api.GoModuleFunc(c.Send),
[]api.ValueType{MemorySegment(0).ValueType()}, // params
[]api.ValueType{}). // return values
Export("send").
Instantiate(ctx)
return &module{mod}, err
}

func (c HostConfig) Send(ctx context.Context, mod api.Module, stack []uint64) {
Expand Down Expand Up @@ -82,3 +83,11 @@ func (s MemorySegment) Load(mem api.Memory) ([]byte, bool) {
length := s.Length()
return mem.Read(offset, length)
}

type module struct {
api.Module
}

func (m module) Close(ctx context.Context) error {
return m.Module.Close(ctx)
}

0 comments on commit 3a0ee62

Please sign in to comment.