go-wasm/examples/caller/main.go

37 lines
595 B
Go
Raw Normal View History

2019-08-06 16:03:11 +03:00
package main
import (
"log"
2019-08-21 00:41:49 +03:00
"github.com/vedhavyas/go-wasm"
2019-08-06 16:03:11 +03:00
)
2019-08-21 00:41:49 +03:00
func proxy(b *wasm.Bridge) wasm.Func {
2019-08-20 22:20:20 +03:00
return func(args []interface{}) (i interface{}, e error) {
2019-08-20 23:47:40 +03:00
log.Println("In Go", args)
2019-08-20 22:20:20 +03:00
return b.CallFunc("addition", args)
}
}
2019-08-06 16:03:11 +03:00
func main() {
2019-08-21 00:41:49 +03:00
b, err := wasm.BridgeFromFile("test", "./examples/wasm/main.wasm", nil)
2019-08-06 16:03:11 +03:00
if err != nil {
log.Fatal(err)
}
2019-08-20 22:20:20 +03:00
err = b.SetFunc("proxy", proxy(b))
if err != nil {
panic(err)
}
2019-08-20 04:35:19 +03:00
init, done := make(chan error), make(chan bool)
2019-08-20 04:13:53 +03:00
go b.Run(init, done)
2019-08-20 04:35:19 +03:00
err = <-init
if err != nil {
panic(err)
}
<-done
2019-08-20 23:47:40 +03:00
log.Println("wasm exited", err)
2019-08-06 16:03:11 +03:00
}