go-wasm/simple/caller/main.go

38 lines
610 B
Go
Raw Normal View History

2019-08-06 16:03:11 +03:00
package main
import (
2019-08-20 04:13:53 +03:00
"fmt"
2019-08-06 16:03:11 +03:00
"log"
wasmgo "github.com/vedhavyas/wasm"
)
2019-08-20 22:20:20 +03:00
func proxy(b *wasmgo.Bridge) wasmgo.Func {
return func(args []interface{}) (i interface{}, e error) {
fmt.Println("In Go", args)
return b.CallFunc("addition", args)
}
}
2019-08-06 16:03:11 +03:00
func main() {
2019-08-15 21:12:20 +03:00
b, err := wasmgo.BridgeFromFile("test", "./simple/prog/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 04:13:53 +03:00
fmt.Println("wasm exited", err)
2019-08-06 16:03:11 +03:00
}