1
0
mirror of https://github.com/taigrr/wasm-experiments synced 2025-01-18 04:03:21 -08:00

Try to call Fetch with a callback

This commit is contained in:
Johan Brandhorst 2018-05-12 15:07:32 +01:00
parent 0bc494b8b2
commit 70424ed5a8
2 changed files with 12 additions and 1 deletions

View File

@ -1,10 +1,14 @@
// +build js,wasm
package fetch package fetch
import ( import (
"fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"runtime/js" "syscall/js"
"syscall/js/callback"
) )
type Method int type Method int
@ -61,6 +65,11 @@ func Fetch(req Request) (Response, error) {
} }
init.Set("headers", headers) init.Set("headers", headers)
cb := callback.New(func(args []js.Value) {
fmt.Println(args)
})
promise := js.Global.Call("fetch", req.URL.String(), init) promise := js.Global.Call("fetch", req.URL.String(), init)
promise.Call("then", cb)
return Response{}, nil return Response{}, nil
} }

View File

@ -1,3 +1,5 @@
// +build js,wasm
package main package main
import ( import (