bidirectional communication
This commit is contained in:
4 files changed
+13
-9
No files matched your search
@@ -16,7 +16,7 @@ func main() {
|
||||
init, done := make(chan bool), make(chan error)
|
||||
go b.Run(init, done)
|
||||
<-init
|
||||
res, err := b.CallFunc("printWasm", &[]interface{}{"success call"})
|
||||
res, err := b.CallFunc("printWasm", &[]interface{}{"Hello from Go"})
|
||||
fmt.Println(res, err)
|
||||
err = <-done
|
||||
fmt.Println("wasm exited", err)
|
||||
|
||||
+3
-4
@@ -9,17 +9,16 @@ import (
|
||||
|
||||
// TODO: log seems to cause an issue
|
||||
func printWasm(this js.Value, v []js.Value) interface{} {
|
||||
fmt.Println("Hello from WASM", v)
|
||||
return nil
|
||||
fmt.Println(v[0].String())
|
||||
return "Hello from WASM"
|
||||
}
|
||||
|
||||
func main() {
|
||||
ch := make(chan bool)
|
||||
//fmt.Println("WASM Go Initialized")
|
||||
fmt.Println("WASM-Go Initialized")
|
||||
|
||||
// register functions
|
||||
fun := js.FuncOf(printWasm)
|
||||
js.Global().Set("printWasm", fun)
|
||||
//fmt.Println("Done...")
|
||||
<-ch
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user